-
Notifications
You must be signed in to change notification settings - Fork 8
Description
I have an UltiSnips snippet I use to help me declare JavaScript functions through a process of keyword elimination that looks like this:
snippet "^function" "top level function declaration" r
${1:export ${2:default }}${3:async }function${4:*} ${5:functionName}(${6:params}) {
$7
}$0
As I delete keywords, I wanted to automatically jump to the next tabstop. So, using the Autojump from tabstop when it's empty guide, I updated the snippet to the following:
global !p
from px.snippets import (
advance_jumper,
get_jumper_position,
get_jumper_text,
make_context,
make_jumper
)
def jump_if_blank(snip, positions):
if get_jumper_position(snip) in positions:
if not get_jumper_text(snip):
advance_jumper(snip)
endglobal
context "make_context(snip)"
post_jump "make_jumper(snip, snip.tabstop)"
snippet "^function" "top level function declaration" r
`!p jump_if_blank(snip, [1, 2, 3, 4])
`${1:export ${2:default }}${3:async }function${4:*} ${5:functionName}(${6:params}) {
$7
}$0
endsnippet
The autojumping works when I delete tabstops 2-4, but if I delete tabstop 1, the autojumping then fails for the rest of the tabstops.
I thought maybe the issue might be with the fact that the snippet uses a regex, or perhaps that tabstop 2 is nested inside tabstop 1, but making those changes didn't fix the problem.
I actually got autojumping back for all tabstops simply by adding a space at the very beginning of the snippet, just before tabstop 1:
context "make_context(snip)"
post_jump "make_jumper(snip, snip.tabstop)"
snippet "^function" "top level function declaration" r
`!p jump_if_blank(snip, [1, 2, 3, 4])
` ${1:export ${2:default }}${3:async }function${4:*} ${5:functionName}(${6:params}) {
$7
}$0
endsnippet
The only issue now is that I have that unwanted space. Is there a way to work around this, or is this perhaps a known issue with tabstops at the very beginning of snippets? There's no issue with manual jumping, which is why I've filed the issue here, rather than with UltiSnips.