Trigger specific snippet by function call

Asked by tobyS

Hi,

I want to add a specific snippet by filetype and name manually, without UltiSnips having to take care about the trigger. As far as I could see there is not "expand snippet ($ft $name) here" function, yet. Please correct me, if I'm wrong. That one would solve my problem.

The only way I found to do this would be the UltiSnips_Anon() function. However, then I would need to take care for file management of snippets myself and basically maintain another snippet collection for users of my plugin. Which is not desired.

Would it be possible to expose a function like UltiSnips_Trigger(snipName, ft=&ft) for that purpose?

TIA,
Toby

Question information

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

I do not understand what you want to achieve. Maybe this helps: you can make a new filetype (like snippets.mine) and than use :UltiSnipsAddFiletypes mine whenever you need to. Does this help? If not, please describe the use case you need to fullfill.

Revision history for this message
tobyS (tobias-schlitt) said :
#2

OK, let me explain in more details.

I started the Skeletons plugin (see https://github.com/tobyS/skeletons.vim) which allows you to determine a snippet to deal as a template for newly created files. By now, I just store the snippets (1 per file) on disk and take care of injecting them myself. I read the corresponding file and use UltiSnips_Anon().

Now a feature request is to select the skeleton to use by additional criteria (i.e. matches on the file path). There is no issue in implementing it, but it would require additional snippet management facilities on my side.

Instead of implementing additional snippet management in Skeletons, my idea is to rely on UltiSnips management facilities. What I want to achieve is that users can do

RegisterSkeleton("php", "src/Foo/Bar", "special_class_snippet")

where the first parameter is the file type, the second some matching condition and the third a snippet name (trigger).

So, what I am looking for is an API in UltiSnips that allows me to trigger expansion of a certain snippet, without having its trigger inside the buffer.

I hope my became more clear?

Thanks for your time,
regards,
Toby

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

I now understand what you want to achieve but I fear it is not straightforward currently. Ultisnips does not offer such an API at the moment. I also do not see how it could be easily implemented. I once thought it would separate ultisnips into three sub modules: one as a snippet database that could be read by ft/trigger string/name, one in a trigger library which would detect if a trigger should be launched and the current state of the buffer and the last being the snippets itself which could give out informations about itself to the world. Your request would be nicely handled with such a refatoring.

However, I am short on time and cannot really work on this right now. Your best bet currently is to use feedkeys() and a custom filetype, sorry.

Revision history for this message
tobyS (tobias-schlitt) said :
#4

I fully agree that such a refactoring would help out. Please keep me posted if you every start with it. :)

Thanks for taking the time to dig into this.