Home Download Buy Blog Forum Support

Environment vars in snippets?

Environment vars in snippets?

Postby charlesroper on Thu Jul 14, 2011 8:49 pm

Are envirinment variables supported in snippets as they are in TextMate/E? I can't get them to work. Specifically I'm trying to get ${TM_CSS_SPACE} working in SCSS and ${TM_XHTML} in the HTML package.
charlesroper
 
Posts: 107
Joined: Thu Feb 18, 2010 7:30 am

Re: Environment vars in snippets?

Postby guillermooo on Thu Jul 14, 2011 8:55 pm

Are these set dynamically? I believe vars defined in .tmPreferences files are visible in snippets since a few versions ago, but I don't think others are.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Environment vars in snippets?

Postby charlesroper on Thu Jul 14, 2011 9:03 pm

I don't know how they are done in TextMate, but in E you can set them on a per project basis.

Could you point me to any examples of how they're set in .tmPreferences?
charlesroper
 
Posts: 107
Joined: Thu Feb 18, 2010 7:30 am

Re: Environment vars in snippets?

Postby guillermooo on Thu Jul 14, 2011 9:28 pm

Check Build 2077 release notes.

I suppose you'd create a file similar to this (Comments (C++).tmPreferences for C++):

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>name</key>
   <string>Comments</string>
   <key>scope</key>
   <string>source.c, source.c++, source.objc, source.objc++</string>
   <key>settings</key>
   <dict>
      <key>shellVariables</key>
      <array>
         <dict>
            <key>name</key>
            <string>TM_COMMENT_START</string>
            <key>value</key>
            <string>// </string>
         </dict>
         <dict>
            <key>name</key>
            <string>TM_COMMENT_START_2</string>
            <key>value</key>
            <string>/*</string>
         </dict>
         <dict>
            <key>name</key>
            <string>TM_COMMENT_END_2</string>
            <key>value</key>
            <string>*/</string>
         </dict>
         <dict>
            <key>name</key>
            <string>TM_COMMENT_DISABLE_INDENT_2</string>
            <key>value</key>
            <string>yes</string>
         </dict>      
      </array>
   </dict>
   <key>uuid</key>
   <string>38DBCCE5-2005-410C-B7D7-013097751AC8</string>
</dict>
</plist>


By the way, those TM_COMMENT_* are used by the comment/uncomment command. Not very useful for snippets, but you'd add your own following that pattern. (I've never tried to use such variables in snippets, though...)
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Environment vars in snippets?

Postby charlesroper on Thu Jul 14, 2011 9:39 pm

Excellent, thanks, that's really helpful.
charlesroper
 
Posts: 107
Joined: Thu Feb 18, 2010 7:30 am

Re: Environment vars in snippets?

Postby charlesroper on Thu Jul 14, 2011 9:48 pm

Hmm, still can't get it working. Here's the tmPreferences file I've created:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>name</key>
   <string>spacer</string>
   <key>scope</key>
   <string>source.css, source.scss</string>
   <key>settings</key>
   <dict>
      <key>shellVariables</key>
      <array>
         <dict>
            <key>name</key>
            <string>TM_CSS_SPACE</string>
            <key>value</key>
            <string> </string>
         </dict>
      </array>
   </dict>
   <key>uuid</key>
   <string>0ef292cd-943a-4fb0-b43d-65959c5e6b06</string>
</dict>
</plist>


It doesn't recognise the space as the <string> value. If I put another character in there, it gets correctly injected. Is there any way I can insert some sort of escaped space?
charlesroper
 
Posts: 107
Joined: Thu Feb 18, 2010 7:30 am

Re: Environment vars in snippets?

Postby guillermooo on Thu Jul 14, 2011 9:51 pm

I'm not really good with XML, but maybe a CDATA section like in the .sublime-snippet files?
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Environment vars in snippets?

Postby charlesroper on Thu Jul 14, 2011 10:01 pm

Yes, that did it. Nice one, thanks, I am indebted to you. Here's my final file: https://gist.github.com/1083560 saved as spacer.tmPreference in my SCSS package. :D
charlesroper
 
Posts: 107
Joined: Thu Feb 18, 2010 7:30 am

Re: Environment vars in snippets?

Postby guillermooo on Thu Jul 14, 2011 10:04 pm

No problem! :)
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Yahoo [Bot] and 17 guests