Sublime Forum

Environment vars in snippets?

#1

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.

0 Likes

How to set variables like TM_XHTML?
#2

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.

0 Likes

#3

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?

0 Likes

#4

Check Build 2077 release notes.

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

[code]<?xml version="1.0" encoding="UTF-8"?>

name Comments scope source.c, source.c++, source.objc, source.objc++ settings shellVariables name TM_COMMENT_START value // name TM_COMMENT_START_2 value /* name TM_COMMENT_END_2 value */ name TM_COMMENT_DISABLE_INDENT_2 value yes uuid 38DBCCE5-2005-410C-B7D7-013097751AC8 [/code]

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

0 Likes

#5

Excellent, thanks, that’s really helpful.

0 Likes

#6

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

[code]<?xml version="1.0" encoding="UTF-8"?>

name spacer scope source.css, source.scss settings shellVariables name TM_CSS_SPACE value uuid 0ef292cd-943a-4fb0-b43d-65959c5e6b06 [/code]

It doesn’t recognise the space as the value. If I put another character in there, it gets correctly injected. Is there any way I can insert some sort of escaped space?

0 Likes

#7

I’m not really good with XML, but maybe a CDATA section like in the .sublime-snippet files?

0 Likes

#8

Yes, that did it. Nice one, thanks, I am indebted to you. Here’s my final file: gist.github.com/1083560 saved as spacer.tmPreference in my SCSS package. :smiley:

0 Likes

#9

No problem! :smile:

0 Likes