Sublime Forum

What's wrong with this snippet?!

#1

Hi all!
Can anyone tell me why this isn’t working?

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

0 Likes

Three key bindings for "
Usage of $TM_SELECTED_TEXT
#2

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.

0 Likes

#3

but there are plenty of other snippets already in ST2 which make use of TM_SELECTED_TEXT. This can’t be !!

0 Likes

#4

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?

0 Likes

#5

e.g. the javascript if else snippet. (Packages\JavaScript\if-___-else.sublime-snippet)

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

0 Likes

#6

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

view.run_command('insert_snippet', {'name':'Packages/JavaScript/if.sublime-snippet'})
0 Likes

#7

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 !

0 Likes

#8

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!

0 Likes