Skip to content

Commit

Permalink
[Python] Add case/match indentation rules (sublimehq#3089)
Browse files Browse the repository at this point in the history
Fixes sublimehq#3086

This commit adds indentation rules for structural pattern matching.

Those keywords need to be followed by at least one non-colon token.

Note:

It only adds `increaseIndentPattern` rules as adding `case` to
`decreaseIndentPattern` pattern would cause the first `case` after a
`match` line to not be indented correctly.
  • Loading branch information
deathaxe authored Oct 14, 2021
1 parent 4bd58e5 commit bf03198
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Python/Indentation Rules.tmPreferences
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@
<key>decreaseIndentPattern</key>
<string>^\s*(elif|else|except|finally)\b.*:</string>
<key>increaseIndentPattern</key>
<string>^\s*(class|(\basync\s+)?(def|for|with)|elif|else|except|finally|if|try|while)\b.*:\s*$</string>
<string><![CDATA[(?x)
^\s*
(
# declaration or control flow keywords
(
( async\s+ )? ( def | for | with )
| class | elif | else | except | finally | if | try | while
) \b
# pattern matching keyword followed by at least one non-whitespace token
| ( case | match )\b \s* [^:]
)
# terminated by colon and followed only by optional whitespace or comment
.* : \s* (\#.*)? $
]]></string>
<key>disableIndentNextLinePattern</key>
<string></string>
</dict>
Expand Down

0 comments on commit bf03198

Please sign in to comment.