Of the 243 colour schemes currently registered on TmThemeEditor, I noticed that almost none of them use scope selector operators.
The operators are very useful for situations like this:
(text.html | text.xml) & (meta.tag entity)
I think the reason they're so rarely used by colour scheme designers is that they're poorly documented. They're not mentioned at all in the official docs for ST2 or ST3, or in the unofficial docs for colour schemes. The unofficial docs for syntax definitions mention scope selectors, but not the operators.
Where can I find documentation of the scope selector operators supported by Sublime Text?
Scopes are dotted strings, specified from least-to-most specific. For example, the if keyword in PHP could be specified via the scope name keyword. control. php . Sublime Text supports TextMate language grammars, and inherited its default syntaxes from various open-source bundles.
A basic selector specifies one or more scope names, and is matched against a token's scope names starting with the left-most scope.
To enable Syntax Highlighting click on “View” in the top bar, then hover your mouse over “Syntax”, and select your programming language from the list. Alternatively, if you save a document with a supported file extension, Sublime Text 3 will automatically apply the Syntax Highlighting for that language.
Go to Tools | Packages | Package Development | New Syntax Definition. Save the new file in your Packages/User folder as a . YAML-tmLanguage file.
The operators, in order of precedence (highest first), are:
(
)
Grouping&
Intersection-
Asymmetric Difference (Relative Complement)|
Union,
CommaThe file format of colour scheme files (.tmTheme
) is inherited from TextMate.
Here are some relevant links and quotes from TextMate's documentation, regarding scope selector operators:
string, comment
."(a | b) & c - d
would select the
scope which is not matched by d
, and matched by both c
, and a
or b
."#
to expand in
source.ruby string
but we don't want it for string source
(embedded code in strings). For this
we can now set the scope to: (source.ruby string) - (string source)
. I added the parentheses for
clarity, they are not necessary (since -
has lowest precedence)."Allan Odgaard (the creator of TextMate) provided some very helpful responses to questions about scope selector operators on the TextMate mailing list. The thread is archived here, and the original messages are here: 1, 2, 3, 4, 5, 6. This response is particularly helpful:
scopes are matched literally (e.g.
string
). These can form a “descendent selector” e.g.source.ruby string
, and for descendent selectors one can take the union (|
or,
), the intersection (&
), or the asymmetric difference (-
).one can also group with parenthesis. The reason though that both
,
and|
can be used for union is that,
was introduced long before the other operators (mimics CSS syntax), so when&
was added, I felt that there should be|
and|
has higher precedence than,
it is the operator with lowest precedence, so e.g.:a - b | c & d, e - f | g & h ⇔ (a - b | c & d), (e - f | g & h)
TextMate supports other operators which are not supported by Sublime Text, including
*
, ^
, >
, $
, L:
, R:
, B:
. These are documented here:
1,
2,
3,
4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With