From e0f484d20e5beb0280f5a751f1f95c1b8b1be61c Mon Sep 17 00:00:00 2001 From: deathaxe Date: Mon, 25 May 2026 11:57:10 +0200 Subject: [PATCH] Enable extending syntaxes to override indentation constrints This commit introduces `no_indent` variable, inspired by Bash, to enable extending syntaxes to override indentation constraints. Use cases: - embed powershell in indented fenced code blocks in Markdown - embed powershell in YAML files, such as Github Action workflows Alternative: A more general and easier to use approach would be to accept ST not tracking indentation and just allow to terminate HEREDOCs regardless leading whitespace in general. --- PowerShell.sublime-syntax | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index f69ebfb..6a467c8 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -1082,7 +1082,7 @@ contexts: - match: (?={{csharp_indicator}}) set: scope:source.cs.embedded.powershell with_prototype: - - match: (?=^{{single_quote}}@) + - match: (?={{no_indent}}{{single_quote}}@) pop: 1 - match: '{{single_quote}}{2}' scope: constant.character.escape.powershell @@ -1091,8 +1091,9 @@ contexts: inside-single-quoted-heredoc-string: - meta_include_prototype: false - meta_scope: meta.string.powershell string.quoted.single.heredoc.powershell - - match: ^{{single_quote}}@ - scope: punctuation.definition.string.end.powershell + - match: '{{no_indent}}({{single_quote}}@)' + captures: + 1: punctuation.definition.string.end.powershell pop: 1 - match: '{{single_quote}}{2}' scope: constant.character.escape.powershell @@ -1108,8 +1109,9 @@ contexts: inside-double-quoted-heredoc-string: - meta_include_prototype: false - meta_scope: meta.string.interpolated.powershell string.quoted.double.heredoc.powershell - - match: ^{{double_quote}}@ - scope: punctuation.definition.string.end.powershell + - match: '{{no_indent}}({{double_quote}}@)' + captures: + 1: punctuation.definition.string.end.powershell pop: 1 - include: escape-sequences - include: string-interpolations @@ -1120,7 +1122,7 @@ contexts: - match: (?={{csharp_indicator}}) set: scope:source.cs.embedded.powershell with_prototype: - - match: (?=^{{double_quote}}@) + - match: (?={{no_indent}}{{double_quote}}@) pop: 1 - include: escape-sequences - include: else-pop @@ -1425,6 +1427,9 @@ variables: )\b shebang_language: \b(?:pwsh|powershell)\b + # Indentation and whitespace patterns + no_indent: ^ + # Attributes attributes: |- \b(?xi: