Snippets in current scope

Asked by petobens

In order to complete snippets I have this in my vimrc

set completefunc=SnipComplete
function! SnipComplete(findstart, base)
    if a:findstart
        let line = getline('.')
        let start = col('.') - 1
        while start > 0 && line[start - 1] =~ '\a'
            let start -= 1
        endwhile
        return start
    else
        let suggestions = []
        for entry in keys(UltiSnips_SnippetsInCurrentScope())
            if entry =~ '^' . a:base
                call add(suggestions, entry)
            endif
        endfor
        return suggestions
endfunction

It works fine but I was wondering whether is possible for the popup menu not only to show the snippet "trigger" but also the snippet "description".
Thanks!

PS: There is a typo in Section 3.5 of the documentation. Where it says:

     UltiSnips provides two functions for extending core functionality.
It should say:
   UltiSnips provides three functions for extending core functionality.

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:

This question was reopened

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

I fixed the error in the docs. Thanks for reporting this.

You could look up the descriptions in the snippet manager... Also, there is a plugin for exactly what you want to do. Have you had a look at this? It is also described in the UltiSnips docs and was the main reason why the UltiSnips_SnippetsInCurrentScope was implemented in the first place.

http://www.vim.org/scripts/script.php?script_id=4276

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

The UltiSnips_SnippetsInCurrentScope() returns a dictionary where keys are "triggers" and elements are "description"?
Something like

        {"trigger" : "description" , "trigger" : "description"}
If that is the case I need a way to modify the for loop and the conditional in my function to check for triggers and print both trigger and descriptions in the popup menu. I read the docs and looked into the plugin but I don't think I need to use two plugins when a simple function suffices.

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

See :echo UltiSnips_SnippetsInCurrentScope(). It does return trigger->description

You can see a sample how to use it here: https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt#L448

The rest you can find in the Vim help about scripting.

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

Thanks SirVer, that solved my question.

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

One minor thing, if I have a snippet like this

    snippet "foo?" "foo" rw
    barbaz$0
    endsnippet

And I do
    :echo UltiSnips_SnippetsInCurrentScope()

The regular expression snippet doesn't appear. Is that correct? I'm probably doing something wrong and I'm sorry to bother you again. Thanks!

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

No worries, the issue you are running into is a real one. See bug 1171276 for more information.

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

Thanks SirVer, that solved my question.