Problems with snip anon

Asked by petobens

I have a fixme snippet written like this

    snippet FM "Fixme" w
    `!p
    cms, fmr1, fmr2 = fold_marker()
   snip.rv = cms` FIXME: ${1:description} <`!v strftime("%d/%m/%Y")`> `!p
   snip.rv = cms`$0
   endsnippet

And an anon snippet (in my vimrc file) to complete parenthesis:

    inoremap <silent> (( ((<C-R>=UltiSnips_Anon('(${1:${VISUAL}})', '((', '', 'i')<cr>

If in an empty buffer I type "FM<tab>" and then "((" instead of getting:

    /* FIXME: () <06/09/2013> /*

y get:

    /* FIXME: () <06/09/20106/09/2013/*/*

Another problem with anon snips is found with the following integral snippet used in tex files:

    snippet int "Integral" w
    \int_{0}^{1}\!${1:function}\mathrm{d}${2:variable}$0
    endsnippet

If in the first placholder (function) I write "f()" and then go to the next placholder, "d}variab" is selected instead of "variable".

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
SirVer (sirver) said :
#1

well, <c-r> seems to be somewhat differently handled inside of Vim, so UltiSnips does not work with it, and it fails in really strange places too. I guess this could be called a bug - but do not hold your breath for it being tracked down. Vim is just to fragile to be predicted realiably in this case.

Revision history for this message
petobens (ferrari-pedro) said :
#2

So basically my option is to switch some plugin that supports automatic closing of quotes, parenthesis, brackets, etc.? I really liked the anon snippets idea.

Revision history for this message
petobens (ferrari-pedro) said :
#3

Another question: the nesting problem with anon snippets has not been solved?

Revision history for this message
SirVer (sirver) said :
#4

#2: the best option would be to track this issues down and provide a fix, really. UltiSnips comes with an extensive test suite, it should be easy to add this to the tests and then fix it without any regressions - it is just leg work.

#3: same answer really.

Revision history for this message
petobens (ferrari-pedro) said :
#5

If the problem is <c-r> maybe a <expr> mapping could be used instead? I tried the following:

            inoremap <silent><expr>(( "((" . UltiSnips_Anon('(${1:${VISUAL}})', '((', '', 'i')

But without success. How can I use anon snippets with <expr> mappings?

Revision history for this message
Best SirVer (sirver) said :
#6

What you are running into here is the model of Vim. Vim does not really allow plugins the deep integration that UltiSnips needs (i.e. keeping track of multiple text locations and changing them with every keystroke/cursor movement), so UltiSnips is based on a bunch of hacks and tricks that simulate user input in some places or rely on undocumented behavior in Vim in other places.

It so comes that for mappings, Vim decided to make things work differently: CursorMovedI autocommand is called less frequently and user commands are not played in the correct order (they are queued up till the end of the mapping it seems). This breaks UltiSnips in those scenarios. What you want to do will only work out when other work arounds for Vims limitations are found - this is mostly a trial and error approach, but should be easy give that we have a huge test suite that can tell you if you succeeded or not in finding other ways to move around and select text and so on.

tl; dr - I do not know why your particular mapping doesn't work, but it is definitively a problem with Vim doing something differently when typing compared to running a mapping. This might be solvable, but for now, Vim is just broken in that regard - patches are welcome to work around in UltiSnips.

Revision history for this message
petobens (ferrari-pedro) said :
#7

Thanks SirVer, that solved my question.