Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippets - custom variables (.sublime-options files?) #226

Open
keith-hall opened this issue Nov 22, 2016 · 6 comments
Open

Snippets - custom variables (.sublime-options files?) #226

keith-hall opened this issue Nov 22, 2016 · 6 comments
Labels

Comments

@keith-hall
Copy link
Contributor

The snippets documentation refers to custom variables and states that they can be defined in .sublime-options files. https://github.com/guillermooo/sublime-undocs/blame/8a3b31288b1e329263c65701b5c133dc8755bc27/source/extensibility/snippets.rst#L105

However, there is no other mention of .sublime-options files in the documentation, specifically, what file format they should be. Is this information actually true?

In my experience, custom variables can be defined in tmPreferences files, in the shellVariables dict section. As you know, shellVariables are used to define TM_COMMENT_START and TM_COMMENT_END, which can be used in snippets. Example: https://github.com/sublimehq/Packages/blob/4db940a44b74727ade298927d5ffdb8826fc9769/HTML/Comments.tmPreferences#L14-L16

It therefore stands to reason that other variables can be defined here too. Example/proof:

<?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_COMMENT_START</string>
                <key>value</key>
                <string>&lt;!-- </string>
            </dict>
            <dict>
                <key>name</key>
                <string>TM_COMMENT_END</string>
                <key>value</key>
                <string> --&gt;</string>
            </dict>
            <dict>
                <key>name</key>
                <string>HELLO_WORLD</string>
                <key>value</key>
                <string>wow!</string>
            </dict>
        </array>
    </dict>
</dict>
</plist>

Snippet:

<snippet>
    <content><![CDATA[
Hello, ${1:this} is a ${2:snippet}. $HELLO_WORLD
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <!-- <scope>source.python</scope> -->
</snippet>

Output when inserting snippet in a HTML file:

Hello, this is a snippet. wow!

Therefore, please can the documentation be updated to reflect the facts.

@FichteFoll
Copy link
Collaborator

I feel like I've read this before ...? But yeah, this is definitely a (known) error.

@keith-hall
Copy link
Contributor Author

I had the idea I've mentioned it before, but I couldn't find it anywhere... if it is a dupe, I apologise!

@davipatti
Copy link

I cannot reproduce keith-hall's original post. Further documentation on how to implement custom variables for snippets would be really appreciated.

@luisobo
Copy link

luisobo commented Oct 4, 2017

I'm on the same boat. I could reproduce thee example, defining custom variables in a Default.tmPreferences file under User.

I can confirm that the documentation seems wrong.

@FichteFoll
Copy link
Collaborator

The documentation is objectively wrong on this part. I haven't gotten around to working on it, however. Pull requests are welcome.

@apjanke
Copy link

apjanke commented Mar 23, 2019

Ping on this. Any progress? I'm trying to get $TM_FULLNAME an $TM_YEAR in the Octave-function.sublime-snippet from the Matlab package working, but not having any luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants