Home Download Buy Blog Forum Support

What's wrong with this snippet?!

What's wrong with this snippet?!

Postby sfranky on Fri Oct 14, 2011 12:52 pm

Hi all!
Can anyone tell me why this isn't working?
Code: Select all
<snippet>
    <content><![CDATA[
\begin{itemize}
$TM_SELECTED_TEXT
\end{itemize}
]]></content>
    <tabTrigger>im</tabTrigger>
    <scope>text.tex.latex</scope>
    <description>Enclose in  itemize</description>
</snippet>

It's not putting my selected text within the itemize environment, it creates the environment but puts no text in it... If I implement this with a keyboard binding instead, it works fine!!
Am I doing something wrong?
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

Re: What's wrong with this snippet?!

Postby guillermooo on Fri Oct 14, 2011 1:01 pm

I don't think anything's wrong with your snippet, but, to my knowledge, what you want to do isn't possible. The $TM_SELECTED_TEXT variable won't be available when you fire off the snippet by its tab trigger. I've never used Textmate, so I don't know whether it does that.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: What's wrong with this snippet?!

Postby sfranky on Fri Oct 14, 2011 1:08 pm

but there are plenty of other snippets already in ST2 which make use of TM_SELECTED_TEXT. This can't be !!
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

Re: What's wrong with this snippet?!

Postby guillermooo on Fri Oct 14, 2011 1:18 pm

Then maybe I'm not understanding what you want to do. Can you give an example of a snippet that does what you're saying?
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: What's wrong with this snippet?!

Postby sfranky on Fri Oct 14, 2011 1:28 pm

e.g. the javascript if else snippet. (Packages\JavaScript\if-___-else.sublime-snippet)
Code: Select all
<snippet>
    <content><![CDATA[if (${1:true}) {${0:$TM_SELECTED_TEXT}} else{};]]></content>
    <tabTrigger>ife</tabTrigger>
    <scope>source.js</scope>
    <description>if … else</description>
</snippet>


From what I understand,
If i type ife<tab> and I have previously selected some text, it should put the text somewhere in my if statement.
This isn't working!! I can't make any example like this work! (yes, i have set the syntax as javascript)
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

Re: What's wrong with this snippet?!

Postby guillermooo on Fri Oct 14, 2011 1:40 pm

I can only make it work as you describe by inserting the snippet from the api:

Code: Select all
view.run_command('insert_snippet', {'name':'Packages/JavaScript/if.sublime-snippet'})
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: What's wrong with this snippet?!

Postby sfranky on Fri Oct 14, 2011 2:01 pm

You re right, I tried it right now and it works. So the other way doesn't work for you either? Maybe it's not supposed to work like this then?
thanks for your help !
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

Re: What's wrong with this snippet?!

Postby sfranky on Sat Oct 15, 2011 10:29 am

Thanks very much sublimator, that was really informative and helpful!!
I had to change the formatting a little though, I don't know why, it would report errors, even in the syntax highlighting. (this JSON thing is not very reader friendly, to a non-programmer anyway)
Anyway, it works perfect now !! Thanks again!
sfranky
 
Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], vitaLee and 28 guests