Problem with UltiSnips_ExpandSnippet()

Asked by petobens

I'm writing a mapping to expand snippets with <CR> after they are shown with neocomplete plugin. First note that in order to expand snippets with <C-s> I have the following setting in my vimrc.

    let g:UltiSnipsExpandTrigger="<C-s>"

Taking this into account the mapping to expand the snippets with <CR> and neocomplete is

    imap <expr><CR> pumvisible() ?
     \ (len(keys(UltiSnips_SnippetsInCurrentScope())) > 0 ?
      \ neocomplete#close_popup()."\<C-s>" : neocomplete#close_popup()) : "\<CR>"

This works nicely however I wanted to make the mapping none recursive. However with

    inoremap <expr><CR> pumvisible() ?
     \ (len(keys(UltiSnips_SnippetsInCurrentScope())) > 0 ?
      \ neocomplete#close_popup()."\<C-s>" : neocomplete#close_popup()) : "\<CR>"

a "^S" character is inserted instead of expanding the snippet. Therefore I tried a more general mapping:

inoremap <expr><CR> pumvisible() ?
  \ (len(keys(UltiSnips_SnippetsInCurrentScope())) > 0 ?
  \ neocomplete#close_popup().UltiSnips_ExpandSnippet() : neocomplete#close_popup()) : "\<CR>"

With this mapping Ultisnips gives an error that essentially is

    Error detected while processing function UltiSnips_ExpandSnippet:
    E523: Not allowed here

So, how I can replace the recursive '\<C-s>" mapping with a non recursive mapping that uses the more general UltiSnips_ExpandSnippet() without getting an error? Thanks!

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
Best SirVer (sirver) said :
#1

That is more VimL foo than I am able to parse. Sorry, I cannot help debug you this. But I can give you more useful advice: ditch neocomplcache and switch to the strictly more powelful youcompleteme: https://github.com/Valloric/YouCompleteMe . It does all that neocomplcache does, but is much faster, better written and comes with build in support for UltiSnips.

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

Okay. Thanks anyway. I will stick with necomplete because i personally find it superior .

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

Thanks SirVer, that solved my question.

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

that surprises me. did you ever try youcompleteme? I guess it is mostly habit - i switched from neocomplcache and there is nothing I ever missed. But sure, whatever floats your boat - sorry that I could not be more help.

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

Yes I tried it, but I hard a really hard time trying to make it work under Windows so I ended returning to neocomplcache which then evolved into neocomplete. No need to be sorry, I finally got my mapping to work after a bit of testing:

inoremap <silent><expr><CR> pumvisible() ?
    \ (len(keys(UltiSnips_SnippetsInCurrentScope())) > 0 ?
    \ neocomplete#close_popup()."\<C-c>l:call UltiSnips_ExpandSnippet()\<CR>" :
    \ neocomplete#close_popup()) : "\<CR>"

Thanks for a great plugin and excellent support!

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

In fact the ability to expand an Ultisnips snippet with <CR> is still (as far as I understand) and open issue in YouCompleteMe:
https://github.com/Valloric/YouCompleteMe/issues/420

Revision history for this message
Brett Campbell (invsblduck) said :
#7

Sorry for the late bump - this is for future users who find this thread, like I have.

YCM is far and away what I consider excellence in software--well thought-out, well-documented, and written in C++ for performance. At least partly by an intelligent person working for Google.

neocomplete, though quite helpful, felt more like an encounter with a crackhead in a sketchy alley (that doesn't mean it's "bad"). Take it FWIW.

So for all you cloud-hipster, crank-yanking little ankle biters out there trying to work the Vim, YCM seems pretty epic.

You're welcome.