-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathScope.txt
57 lines (54 loc) · 7.08 KB
/
Scope.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Scope is a key concept in Sublime Text, similar to Textmate's scope http://manual.macromates.com/en/scope_selectors
:Scope: is a named text regions in a buffer, i.e:
Have a .txt file like this:
Sublime Text peeks at [[a named scope]] to get contextual information
Via .tmLanguage, we define:
All text inside *.txt as text.Plain [[tmlanguage.txt#<key>scopeName</key>]]
The text in side [[]] as internal.link.abc such as <string>\[\[[^\]]+\]\]</string>
=> the text region "[[a named scope]]" has scope (aka scope selector) = text.Plain internal.link.abc
Via .tmtheme, we define all text regions, whose scope = internal.link.abc as green color
Via .py, we define plugin which do action X if cursor is placed inside that region, and action Y if not
Scope name can be combined
As dot-separated, i.e: internal.link.abc
You can define text pattern for "internal", for "link", for "internal.link", for "internal.link.abc" separately
If a text region match multiple scope names, then only 1 scope name is used [[#Ranking Matches]]
=> you could have a key binding activated only in Python source code but not in Plain Text
As comma-separated, i.e: Text.string, Text.comment => Match either Text.string OR Text.comment (Text.comment has higher priority)
As space-separated, i.e: text.Plain internal.link.abc => Match exactly
Ranking Matches (Highest to lowest):
Element deepest down in the scope wins
Match most of the deepest element
In the case of a tie, Rules 1 and 2 applied again to the scope selector when removing the deepest element
Example 1:
source.php string.quoted
Element deepest down in the scope wins: string > source.php
Match most of the deepest element => string.quoted > string
Incase a tie: text source string > source string
Example 2:
internal.link = All text inside *.wzt file
internal.link.abc = All text inbetween [[ ]]
then [[blah blah]] in *.wzt file will match both scope, but internal.link.abc will be used due to higher Ranking
Scope name convention
Facilitate syntax highlighing
You can only use only 1 .tmtheme at a time
a few typical scopes are supported by most .tmtheme i.e:
<string>comment.line</string> Gray
<string>comment.block</string> Gray
<string>constant.numeric</string> Purple
<string>constant.language</string> Purple
<string>entity.name.function</string> Red
<string>keyword.control</string> Red
<string>keyword.operator</string> Red
<string>keyword.command</string> Red
<string>keyword.other</string> Red
<string>meta.structure.linebreak</string>
<string>punctuation</string>
<string>storage.type.primitive.array</string>
<string>string</string>
<string>variable.parameter</string> Orange
=> add syntax-specific to the end such as entity.name.function.py ; keyword.control.vbs
For a color to work on different .tmtheme: use comma-separated scope name, i.e: entity.name.function.py, class.variable.py
Steps
use .tmLanguage to define text regions as entity.name.function.py
use .tmtheme to define color for entity.name.function
use .py to do specific actions on .py