Sublime Forum

Getting $TM_FULLNAME and $TM_YEAR working on macOS

#1

Hi folks. I’m running Sublime Text 3 on macOS 10.14.3. I’d like to get the $TM_FULLNAME and $TM_YEAR variables working, so I can use them in Snippets like the “octfun” snippet in the Matlab package, which does this:

<snippet>
	<content><![CDATA[## Copyright (C) ${TM_YEAR} $TM_FULLNAME
##
## This program is free software; you can redistribute it and/or modify

Right now, they’re just getting filled in with blanks.

Anyone know what I can configure to make these work? It’s fine if I have to just configure them manually in a settings file somewhere; I just don’t know where that would be.

0 Likes

#2

you could define TM_YEAR in a tmPreferences file like mentioned in


not sure about TM_FULLNAME, whether setting it would override the built in one or not, but you could always name it something different

1 Like

#3

Hmmm. I’m not sure I understand how to get this to work.

I created a file “/Users/janke/Library/Application Support/Sublime Text 3/Packages/User/Default.tmPreferences”. I think Sublime Text is recognizing it, because when I "touch"ed it to create a blank file and opened it in Sublime Text, it popped up a dialog about invalid XML in that file.

I created it with these contents:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comments</string>
    <key>scope</key>
    <string>text.html</string>
    <key>settings</key>
    <dict>
        <key>shellVariables</key>
        <array>
            <dict>
                <key>name</key>
                <string>TM_FULLNAME</string>
                <key>value</key>
                <string>Andrew Janke</string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_YEAR</string>
                <key>value</key>
                <string>2019</string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_FULLNAME_TEST</string>
                <key>value</key>
                <string>Andrew Janke</string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_YEAR_TEST</string>
                <key>value</key>
                <string>2019</string>
            </dict>
        </array>
    </dict>
</dict>
</plist>

But when using the snippet that uses $TM_FULLNAME and $TM_YEAR, they still aren’t substituted.

Thinking those might be special variables, I created a new Snippet that uses $TM_FULLNAME_TEST and $TM_YEAR_TEST (which are defined in the Default.tmPreferences file), like this:

<snippet>
  <content><![CDATA[## Copyright (C) ${TM_YEAR_TEST} $TM_FULLNAME_TEST
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
[...]
]]></content>
  <tabTrigger>octklass</tabTrigger>

But when I use that snippet, the variables are still not filled in.

0 Likes

#4

try using an empty scope selector in the tmPreferences file or text, source instead of text.html, to make the variables apply everywhere

1 Like

#5

Haha! Using the empty scope selector in Default.tmPreferences did the trick.

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comments</string>
    <key>scope</key>
    <string></string>
    <key>settings</key>

Thank you!

0 Likes