Home Download Buy Blog Forum Support

Environment variable in Snippet

Environment variable in Snippet

Postby jdcpar5 on Fri Apr 27, 2012 3:48 pm

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
Code: Select all
<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: http://goo.gl/Vn6Rd

-----
Using Sublime Text 2, Build 2181 on Max OS x 10.7
jdcpar5
 
Posts: 2
Joined: Fri Apr 27, 2012 2:29 pm

Re: Environment variable in Snippet

Postby wuub on Fri Apr 27, 2012 4:27 pm

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 :) https://bitbucket.org/wuub/magicsnippets/overview
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Environment variable in Snippet

Postby C0D312 on Fri Apr 27, 2012 5:44 pm

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...
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Environment variable in Snippet

Postby wuub on Fri Apr 27, 2012 5:59 pm

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.
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Environment variable in Snippet

Postby C0D312 on Fri Apr 27, 2012 6:43 pm

wuub wrote: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.


@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. :( Plus magic > SMART, so you already have an advantage.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Environment variable in Snippet

Postby wuub on Fri Apr 27, 2012 7:05 pm

:) 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 :)
SublimeREPL via Package Control & SublimePTY dev/pre-alpha. Donations are appreciated, but not required :) Twitter: @wuub
wuub
 
Posts: 218
Joined: Wed Aug 10, 2011 8:16 am
Location: Poland

Re: Environment variable in Snippet

Postby C0D312 on Fri Apr 27, 2012 8:51 pm

no worries. just didn't want to offend.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Environment variable in Snippet

Postby jdcpar5 on Sun Apr 29, 2012 10:19 pm

Thanks. I think? :)
jdcpar5
 
Posts: 2
Joined: Fri Apr 27, 2012 2:29 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 28 guests