Skip to content

Commit a0ceb7f

Browse files
authored
Add support for syntax-based folding (SublimeText#191)
Regions, comment blocks, and heredocs can now be folded. Additionally, region names are now searchable using ctrl-r.
1 parent 7b9767e commit a0ceb7f

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

Fold.tmPreferences

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plist version="1.0">
3+
<dict>
4+
<key>scope</key>
5+
<string>source.powershell</string>
6+
<key>settings</key>
7+
<dict>
8+
<key>foldScopes</key>
9+
<array>
10+
<dict>
11+
<key>begin</key>
12+
<string>meta.fold.begin</string>
13+
<key>end</key>
14+
<string>meta.fold.end</string>
15+
</dict>
16+
<dict>
17+
<key>begin</key>
18+
<string>punctuation.definition.comment.block.begin</string>
19+
<key>end</key>
20+
<string>punctuation.definition.comment.block.end</string>
21+
<key>excludeTrailingNewlines</key>
22+
<false/>
23+
</dict>
24+
<dict>
25+
<key>begin</key>
26+
<string>string.quoted.double.heredoc punctuation.definition.string.begin</string>
27+
<key>end</key>
28+
<string>string.quoted.double.heredoc punctuation.definition.string.end</string>
29+
<key>excludeTrailingNewlines</key>
30+
<false/>
31+
</dict>
32+
<dict>
33+
<key>begin</key>
34+
<string>string.quoted.single.heredoc punctuation.definition.string.begin</string>
35+
<key>end</key>
36+
<string>string.quoted.single.heredoc punctuation.definition.string.end</string>
37+
<key>excludeTrailingNewlines</key>
38+
<false/>
39+
</dict>
40+
<dict>
41+
<key>begin</key>
42+
<string>punctuation.section.group.begin</string>
43+
<key>end</key>
44+
<string>punctuation.section.group.end</string>
45+
<key>excludeTrailingNewlines</key>
46+
<false/>
47+
</dict>
48+
<dict>
49+
<key>begin</key>
50+
<string>punctuation.section.braces.begin</string>
51+
<key>end</key>
52+
<string>punctuation.section.braces.end</string>
53+
<key>excludeTrailingNewlines</key>
54+
<false/>
55+
</dict>
56+
</array>
57+
</dict>
58+
</dict>
59+
</plist>

PowerShell.sublime-syntax

+16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ contexts:
3535
pop: true
3636

3737
main:
38+
- include: regions
3839
- include: comments
3940
- include: expressions
4041

@@ -808,3 +809,18 @@ contexts:
808809
- match: (?=\()
809810
pop: true
810811
- include: comment-line
812+
813+
regions:
814+
- match: ^\s*((#)\s*(region\b)(?:\s*(\S.*))?(\n?))
815+
captures:
816+
1: comment.line.powershell
817+
2: punctuation.definition.comment.powershell
818+
3: keyword.other.region.begin.powershell
819+
4: meta.toc-list.powershell entity.name.section.powershell
820+
5: meta.fold.begin.powershell
821+
- match: ^\s*((#)\s*(endregion\b).*(\n?))
822+
captures:
823+
1: comment.line.powershell
824+
2: punctuation.definition.comment.powershell
825+
3: keyword.other.region.end.powershell
826+
4: meta.fold.end.powershell

Tests/syntax_test_PowerShell.ps1

+29
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ There is no @platting here!
469469
"@
470470
# <- string.quoted.double.heredoc
471471
# <- string.quoted.double.heredoc
472+
@'
473+
#<- meta.string string.quoted.single.heredoc punctuation.definition.string.begin
474+
A 'single quoted' "heredoc"
475+
'@
476+
#<- meta.string string.quoted.single.heredoc punctuation.definition.string.end
472477

473478
# Numeric constants
474479

@@ -1805,3 +1810,27 @@ function get-number {}
18051810
#<- comment.block comment.documentation.embedded punctuation.definition.keyword.documentation
18061811
#^^^^^^^^^^^^ keyword.other.documentation
18071812
#>
1813+
1814+
#region Test
1815+
#<- punctuation.definition.comment
1816+
#^^^^^^ keyword.other.region.begin
1817+
#<- comment.line.powershell
1818+
# ^^^^ meta.toc-list entity.name.section
1819+
# @@@@ local-definition
1820+
# ^ meta.fold.begin
1821+
#endregion (More comments)
1822+
#<- punctuation.definition.comment.powershell
1823+
#^^^^^^^^^ keyword.other.region.end.powershell
1824+
#<- comment.line
1825+
# ^ meta.fold.end
1826+
1827+
#region
1828+
#<- punctuation.definition.comment
1829+
#^^^^^^ keyword.other.region.begin
1830+
#<- comment.line.powershell
1831+
# ^ meta.fold.begin
1832+
#endregion (More comments)
1833+
#<- punctuation.definition.comment.powershell
1834+
#^^^^^^^^^ keyword.other.region.end.powershell
1835+
#<- comment.line
1836+
# ^ meta.fold.end

0 commit comments

Comments
 (0)