Sublime Forum

Environment variable in Snippet

#1

Iā€™m new to ST2. Trying to use strftime("%a %D") in a snippet with a tab trigger. Iā€™ve hunted around quite a bit, and it seems like I should be able to set a variable $TM_mydate or whatever in a .sublime-options file? I donā€™t see an Options folder when I look in
~/Library/Application Support/Sublime Text 2/Packages/Default/
so I canā€™t see the syntax to use to set $TM_myDate = strftime("%a %D"), but maybe I donā€™t have to?

In my snippet, Iā€™m using

<snippet>
    <content><![CDATA[
#######################
###  `strftime("%a %D")`   ###
#######################
$1
]]></content>
    <!-- Optional: Set a tabTrigger...

what Iā€™d like to appear is:
#######################

Fri 04/27/12

#######################

anyone know the correct syntax to use to include the value of strftime("%a %D") in a snippet? Do I need to create a custom variable in a ā€œsomething.sublime-optionsā€ file like it refers to here: goo.gl/Vn6Rd


Using Sublime Text 2, Build 2181 on Max OS x 10.7

0 Likes

#2

You can try my hack. iā€™ve been using it for several months now to do exactly what you are describing. It evaluates code between backtics on save, doing it after snippet insertion breaks undo stack. There is obviously no documentation :smile: bitbucket.org/wuub/magicsnippets/overview

0 Likes

#3

Or, a better alternative is to use my not-yet-released SMART Snippets plugin.

Thereā€™s still a bunch of bugs and stuff before its ready for primetime, so hold tight.

@wuub: this is awkwardā€¦

0 Likes

#4

I donā€™t follow you COD321, I never said it has bugs, it does exactly what OP wants and Iā€™m using it every day for several months now w/o any problems whatsoever.

I just consider it a hack and donā€™t believe itā€™s intresting enough for general audience to be released as a standalone plugin.

0 Likes

#5

[quote=ā€œwuubā€]I donā€™t follow you COD321, I never said it has bugs, it does exactly what OP wants and Iā€™m using it every day for several months now w/o any problems whatsoever.

I just consider it a hack and donā€™t believe itā€™s intresting enough for general audience to be released as a standalone plugin.[/quote]

@wuub Iā€™m sorry? I was just trying to promote my plugin as healthy competition. My plugin hasnā€™t been released because of some bugs. Iā€™m not saying anything bad about your plugin. Sorry if you misinterpreted what I said. The awkward thing was that I spent several months working on and off on a plugin that I thought no one else thought of. Then I discovered that you already made it. :frowning: Plus magic > SMART, so you already have an advantage.

0 Likes

#6

:smile: oh, I though you were being ironic. You had every reason to be tbh, most of my plugins are severely under-documented and I know it. But I couldnā€™t pass this one, because OP has exactly the same problem i did: automatic dates in snippets.

Edit: sorry for spelling your nick wrong, im on the road, writing this on my phone :smile:

0 Likes

#7

no worries. just didnā€™t want to offend.

0 Likes

#8

Thanks. I think? :smile:

0 Likes