Skip to content
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

Autojump fails when tabstop at the beginning of a snippet #16

Open
paulfioravanti opened this issue Jul 16, 2023 · 0 comments
Open

Autojump fails when tabstop at the beginning of a snippet #16

paulfioravanti opened this issue Jul 16, 2023 · 0 comments

Comments

@paulfioravanti
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant