## What's wrong with this snippet?!

### What's wrong with this snippet?!

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?! 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: 738
Joined: Thu Jul 23, 2009 9:06 am

### Re: What's wrong with this snippet?!

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?!

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: 738
Joined: Thu Jul 23, 2009 9:06 am

### Re: What's wrong with this snippet?!

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?!

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: 738
Joined: Thu Jul 23, 2009 9:06 am

### Re: What's wrong with this snippet?!

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?
sfranky

Posts: 96
Joined: Mon Oct 19, 2009 10:06 pm

### Re: What's wrong with this snippet?!

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