Home Download Buy Blog Forum Support

Snippets for functions with optional arguments

Snippets for functions with optional arguments

Postby gregor.hoch on Fri Apr 27, 2012 7:02 pm

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
Code: Select all
lm(formula, data, subset)

as a snippets, the content would look like this
Code: Select all
<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!

http://readthedocs.org/docs/sublime-tex ... ht=snippet]
gregor.hoch
 
Posts: 144
Joined: Sat Oct 01, 2011 7:54 pm

Re: Snippets for functions with optional arguments

Postby C0D312 on Fri Apr 27, 2012 7:19 pm

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

<content><![CDATA[lm(${1:formula} ${2:[, data]}) ${3:[, subset]})]]></content>
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Snippets for functions with optional arguments

Postby gregor.hoch on Fri Apr 27, 2012 11:21 pm

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!
gregor.hoch
 
Posts: 144
Joined: Sat Oct 01, 2011 7:54 pm

Re: Snippets for functions with optional arguments

Postby C0D312 on Fri Apr 27, 2012 11:36 pm

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! :)
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Snippets for functions with optional arguments

Postby gregor.hoch on Sat Apr 28, 2012 9:10 am

sounds absolutely great! I would be happy to contribute extended snippets for R...
gregor.hoch
 
Posts: 144
Joined: Sat Oct 01, 2011 7:54 pm

Re: Snippets for functions with optional arguments

Postby pier on Sun Nov 11, 2012 10:03 am

C0D312 wrote: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! :)


So how is this plugin going on? :)

Is it possible to handle optional parameters already?
pier
 
Posts: 92
Joined: Fri Jun 15, 2012 2:47 am

Re: Snippets for functions with optional arguments

Postby Virsalus on Mon Nov 24, 2014 1:39 am

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?
Virsalus
 
Posts: 1
Joined: Mon Nov 24, 2014 1:37 am


Return to General Discussion

Who is online

Users browsing this forum: Yahoo [Bot] and 23 guests