Sublime Forum

Snippets for functions with optional arguments

#1

Hi, I has just looking at the documentation for snippets and started wondering whether they somehow support optional arguments for functions?

For example, when I implement

lm(formula, data, subset)

as a snippets, the content would look like this

<content><![CDATA[lm(${1:formula}, ${2:data}) , ${3:subset})]]></content>

But data and subset are optional options (only formula is required). What is the best way to handle this situation with snippets. Is there a way to indicate that parts are optional so that they are not inserted by default but only come up for autocompletion within the function?

Thanks!

readthedocs.org/docs/sublime-tex … ht=snippet]

0 Likes

#2

The most common way to handle this is with square brackets like so:

[pre=#2A2A2A][/pre]

0 Likes

#3

So I guess there is no way to have an auto-completion based on function arguments within snippets? So that ST2 basically offers the function arguments as completion options as part of the snippet (or through a different mechanism)?

thanks!

0 Likes

#4

I’m on a roll with people requesting features that I’ve already incorporated into my plugin.

@gregor: no this is not possible with by default in ST. However, I’m currently developing a plugin that extends the snippet functionality and this will be possible. Unfortunately it still has a lot of work to get done; however, I may open it up to the public soon. Stay tuned! :smile:

0 Likes

#5

sounds absolutely great! I would be happy to contribute extended snippets for R…

0 Likes

#6

[quote=“C0D312”]I’m on a roll with people requesting features that I’ve already incorporated into my plugin.

@gregor: no this is not possible with by default in ST. However, I’m currently developing a plugin that extends the snippet functionality and this will be possible. Unfortunately it still has a lot of work to get done; however, I may open it up to the public soon. Stay tuned! :smile:[/quote]

So how is this plugin going on? :smile:

Is it possible to handle optional parameters already?

0 Likes

#7

Please excuse me for bringing up this old thread again, I have searched around a bit and could not find anything else like it.

Is there any way by now to enable this functionality?

0 Likes