Home Download Buy Blog Forum Support

Advanced Snippets Functionality?

Advanced Snippets Functionality?

Postby EJ12N on Wed May 13, 2009 2:55 pm

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

Code: Select all
<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 :D?

EDIT:Fixed, see below


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

Code: Select all
# ${1/./-/g}
# ${1:$SELECTION}
# ${1/./-/g}


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: Select all
# --------------------------
# Lorem ipsum dolor sit amet
# --------------------------


Now with the following example the regex replacement works wonderful
snippet taken directly from sublimator in one of topics in the forum
Code: Select all
<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! :)
---

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 ;)

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! :D
Last edited by EJ12N on Wed May 13, 2009 6:40 pm, edited 2 times in total.
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Advanced Snippets Functionality?

Postby EJ12N on Wed May 13, 2009 6:39 pm

Ok I got the first snippet to work :)

<binding key="/([\w-]+)/,#,/([\w-]+)/,tab" command="...">


passes arg1 and arg2 good :)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Advanced Snippets Functionality?

Postby EJ12N on Thu May 14, 2009 2:46 pm

Interesting, thanks for the comments nick! :)

Actually you may even be able to do what you want now. The conditionals you mentioned are only run *once* upon first insertion? I think you could very easily do that now.

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...

Marketing is definitely lacking. I really hope you go ahead with this. Sublime deserves more people. More people deserve Sublime.

I know, that should be the motto! LOL

I really hope Jon is reading the forums!
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Advanced Snippets Functionality?

Postby jps on Thu May 28, 2009 1:24 pm

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.
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: Advanced Snippets Functionality?

Postby EJ12N on Thu May 28, 2009 2:35 pm

jps wrote: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.

Okie dokie! is all good, is not like the end of the world like you said :)
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm

Re: Advanced Snippets Functionality?

Postby EJ12N on Sun May 31, 2009 4:09 pm

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
EJ12N
 
Posts: 281
Joined: Tue Apr 21, 2009 5:23 pm


Return to Technical Support

Who is online

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