Search code examples
xmlpackageyamlsublimetext3syntax-highlighting

How to fix a package from Sublime Text that doesn't read its color scheme?


note
  > note.sublime-color-scheme
  > note.sublime-syntax
  > note.tmTheme
  > sample.note

This is how my package structure called note looks like. I created and registered my custom scope name called my.own.scope onto a specific text pattern from .sublime-syntax file and it works just fine without any of the problem in my sample.note file.

Now, I'm trying to style the text what it is hooked by my.own.scope using .sublime-color-scheme file, but ST doesn't style the text at all.

How can I solve this error? I created a new .tmTheme file to fix this problem, but nothing happened either.

Codes from .sublime-syntax;

%YAML 1.2
---
file_extensions:
  - note
scope: text.plain.note

contexts:
  main:
    - match: '^-\s{1,}\w+'
      scope: my.own.scope

Codes from .sublime-color-scheme;

{
    "name": "Note",
    "variables": {
        "black": "hsl(0, 0%, 0%)",
    },
    "globals": {
        "foreground": "",
        "background": "",
        "accent": "",
        "selection": "",
    },
    "rules": [
        {
            "name": "myOwnScope",
            "scope": "my.own.scope",
            "foreground": "var(black)",
        }
    ]
}

Codes from .tmTheme file;

<plist version="1.0">
<dict>
    <key>name</key>
    <string>note</string>
    <key>scopeName</key>
    <string>source.base_scope</string>
    <key>settings</key>
    <array>
        <dict>
            <key>name</key>
            <string>myOwnScope</string>
            <key>scope</key>
            <string>my.own.scope</string>
            <key>settings</key>

            <dict>
                <key>foreground</key>
                <string>#000000</string>
            </dict>
        </dict>
    </array>
    <key>uuid</key>
    <string>41f141d6-0432-43ef-87d0-d509ac95f110</string>
</dict>
</plist>

Solution

  • The first thing to note is that tmTheme and sublime-color-scheme are treated identically once loaded, so in this case what works in one will work in the other as well. Files of both types with the same name will be merged together into one on load. so having a file with the same name in both types will likely cause you confusion and heartache in the future; you should pick one and delete the other. The general advice is to not use tmTheme unless you have a compelling reason to do so, because sublime-color-scheme has more features (e.g. variables).

    The larger issue though, is that based on your question you might be thinking that because the syntax is named note.sublime-syntax, that you need to create a note.sublime-color-scheme in order to set up the colors for it, but that's not how that works.

    The color scheme that Sublime uses is controlled by the color_scheme setting in your Preferences.sublime-settings; so to activate your color scheme you would need to edit your preferences and set color_scheme to note.sublime-color-scheme, for example.

    Likely you don't want to do that though. Your example above contains only a single color rule that will make that text black. When a color scheme is empty, the defaults are a white background and black text, so if that color scheme was in fact active, what you would see is a white window with all text being black by default, and the text matched by your scope would similarly be black, so you would not be able to notice any difference.

    In all likelihood, what you want to do here is choose UI: Customize Color Scheme from the Command Palette or Preferences > Customize Color Scheme from the menu, and then add the single rule entry you have above into the rule section of the file that will open in the right hand pane.

    Doing so will augment your existing color scheme to have the extra rule that colorizes the scope you've added to your sample syntax.