Sublime Forum

Advanced Snippets Functionality?

#1

ok so I am trying to do couple advanced snippets and is not working

[quote]<binding key="/(.+)#(.+)/,tab" command="insertSnippet '...' $1 $2">
pretty self explanatory, anyways, it passes capturing group 1 from regex but it won’t pass any other group from then on…
the second argument is passed as ‘$2’ instead of the text after the “#” sign

Am I missing something or is this a bug :smiley:?
[/quote]

EDIT:Fixed, see below

Also for regex replacement in snippets, works but is REALLY buggy. Try this one for example

[code]# ${1/./-/g}

${1:$SELECTION}

${1/./-/g}[/code]

So whenever I type anything for my comment header, the above section and below should replace anything that im typing with “-”
final result would look something like this

[code]

--------------------------

Lorem ipsum dolor sit amet

--------------------------[/code]

Now with the following example the regex replacement works wonderful
snippet taken directly from sublimator in one of topics in the forum

<content><![CDATA[-module (${1:${TM_FILEPATH/^.*[\\|\/](.*)\.php$/$1/g}}).]]></content>

which it would do -module NAMEOFFILE (without the extension in this case .php)

I would also like to request conditional snippets and for us to be able to run python in them?
like if $PARAM1==’#’ { do this } else { do this one }

something like that, I think it would just be the icing on the cake for snippets, specially ability to run python commands on them! :smile:

Can I get some input on this? Are they bugs are they going to get improved? Jon you still around?

I am compiling a series of screencast and overall doing some “marketing” stuff that I am going to release to jon/public so people can see why sublime IMO is the best sh*t out there for serious coders! lol
I think it will improve popularity of sublime and overall just give the editor and author what it needs, some big kudos and recognition around the world, and more sales of course :wink:

BUT there are a couple things that need to get fixed in order for me to succeed in my “bragging? lol” showcasing of the power of sublime (don’t get me wrong it kicks ass already I am just picky!)

I would greatly appreciate some input from you guys so let me know!

P.S. BTW sublime editor is only reason I started learning/doing python! :smiley:

0 Likes

#2

Ok I got the first snippet to work :smile:

passes arg1 and arg2 good :smile:

0 Likes

#3

Interesting, thanks for the comments nick! :smile:

I know there’s possiblity to do it right now with some sort of plugin using insertInlineSnippet…
What I would like to do is for example in above example, instead of having 2 sublime-snippet files, have just one thx to conditional snippets.

so I could just regex (#|.) to see if we doing a class or id and then in the snippet do something like,
if $PARAM1 == ‘#’ { id="$PARAM2" } if $PARAM1 == ‘.’ { class="$PARAM2" }
and I think that will open up a bunch of possibilities to do a neat lot of stuff with snippets.

I also think regex replacements in snippets needs to get fixed, IMO this is vital to advanced snippet functionality, almost all good textmate snippets have regex on them…
Thanks God we have some sort of it, but is BUGGY, very buggy… I am guessing is because of multiple selections so it gets pretty messy lol…

I know, that should be the motto! LOL

I really hope Jon is reading the forums!

0 Likes

#4

Regex replacement in snippets is a half implemented feature I likely shouldn’t have left in.

Full compatibility with TextMate snippets is going to require some fundamental changes to the way snippets are handled in Sublime. This isn’t the end of the world, but my focus at the moment is on the plugin system.

0 Likes

#5

[quote=“jps”]Regex replacement in snippets is a half implemented feature I likely shouldn’t have left in.

Full compatibility with TextMate snippets is going to require some fundamental changes to the way snippets are handled in Sublime. This isn’t the end of the world, but my focus at the moment is on the plugin system.[/quote]

Okie dokie! is all good, is not like the end of the world like you said :smile:

0 Likes

#6

I am open to anything! Running a callback thru snippets (piping?) that we can use python is all we need really,
there we can do regex transformations and whatnot!
But I agree with the nested snippets functionality it would be awesome to have it, but coding wise (I think) could get really complicated to manage? lol

0 Likes