These are chat archives for SirVer/ultisnips

14th
Feb 2017
Befedo
@Befedo_twitter
Feb 14 2017 18:31

Hi guys ...
I'm trying out the alias example given here. My Snippet-File looks like:

snippet pr "print debug" bw
`!p
prefix = t[1] + ": %q\\n' "
prefix = "{}:{}: {}".format(
    os.path.basename(px.buffer.get().name),
    str(px.cursor.get()[0]),
    prefix
)
`printf 'XXXXXX `!p snip.rv=prefix`$1 >&2
endsnippet

post_jump "px.snippets.expand(snip)"
snippet pd "Description" b
pr$1 >${2:/tmp/debug}
endsnippet

But when I expand the snippet this leads to:

...
NameError: name 'px' is not defined

Executed snippet code:
  1
  2   prefix = t[1] + ": %q\\n' "
  3   prefix = "{}:{}: {}".format(
  4 >     os.path.basename(px.buffer.get().name),
  5       str(px.cursor.get()[0]),
  6       prefix
  7   )
  8

What am I getting wrong? I'm running UltiSnips on Neovim with Python enabled :echo has ('python') is 1.

Thanks for your time and best regards,

Befedo

Befedo
@Befedo_twitter
Feb 14 2017 19:05

Got it ... :)

Had to add:

global !p
def expand(snip):
    if snip.tabstop != 1:
        return
    vim.eval('feedkeys("\<C-R>=UltiSnips#ExpandSnippet()\<CR>")')
endglobal

To my local Snippet-File, to get expansion working.