Skip to content

Commit

Permalink
Revise region-matching regexes and add new fold scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
matteocoder committed Jan 12, 2025
1 parent 1213df6 commit 9ecdc80
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
24 changes: 22 additions & 2 deletions Fold.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,41 @@
<array>
<dict>
<key>begin</key>
<string>punctuation.section.block.begin</string>
<string>meta.fold.begin</string>
<key>end</key>
<string>punctuation.section.block.end</string>
<string>meta.fold.end</string>
</dict>
<dict>
<key>begin</key>
<string>punctuation.definition.comment.block.begin</string>
<key>end</key>
<string>punctuation.definition.comment.block.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>punctuation.definition.string.begin</string>
<key>end</key>
<string>punctuation.definition.string.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.group.begin</string>
<key>end</key>
<string>punctuation.section.group.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
<dict>
<key>begin</key>
<string>punctuation.section.braces.begin</string>
<key>end</key>
<string>punctuation.section.braces.end</string>
<key>excludeTrailingNewlines</key>
<false/>
</dict>
</array>
</dict>
Expand Down
26 changes: 14 additions & 12 deletions PowerShell.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -811,15 +811,17 @@ contexts:
- include: comment-line

regions:
- match: ^(#region\s*(.*))$
captures:
# Applying the punctuation.section.block.begin scope to the entire pattern
# allows Sublime Text to show the region name when it is folded.
1: punctuation.section.block.begin.powershell comment.line.powershell
2: meta.toc-list.powershell
- match: ^#endregion\b
scope: punctuation.section.block.end.powershell comment.line.powershell
push:
- meta_content_scope: comment.line.powershell
- include: pop-at-newline
- include: comment-embedded-docs
- match: ^\s*(#)\s*(region)\b\s*(\S.*)
captures:
1: punctuation.definition.comment.powershell
2: comment.line.powershell
3: meta.toc-list.powershell meta.fold.begin.powershell entity.name.section.powershell
- match: '^\s*(#)\s*(region)\b\s*'
captures:
1: punctuation.definition.comment.powershell
2: comment.line.powershell meta.fold.begin.powershell
- match: '^\s*(#)\s*(endregion\b[^\S\n]*.*)($\n?)'
captures:
1: punctuation.definition.comment.powershell
2: comment.line.powershell
3: meta.fold.end.powershell
7 changes: 4 additions & 3 deletions Tests/syntax_test_PowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1812,9 +1812,10 @@ function get-number {}
#>

#region Test
#<- punctuation.section.block.begin comment.line
# ^^^^ meta.toc-list
#<- punctuation.definition.comment
#^^^^^^ comment.line.powershell
# ^^^^ meta.toc-list meta.fold.begin entity.name.section
# @@@@ local-definition
#endregion (Text after #endregion is optional, but the ISE marks it as a comment as well)
#<- punctuation.section.block.end comment.line
#<- punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line

0 comments on commit 9ecdc80

Please sign in to comment.