Skip to content

Commit

Permalink
Improve indentation of else line under for/while loops
Browse files Browse the repository at this point in the history
FIX: Properly indent `else:` when attached to a `for` or `while`
statement.

Closes codemirror/dev#1363
  • Loading branch information
marijnh committed Mar 28, 2024
1 parent ce4804b commit 0cf3593
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const pythonLanguage = LRLanguage.define({
indentNodeProp.add({
Body: context => indentBody(context, context.node) ?? context.continue(),
IfStatement: cx => /^\s*(else:|elif )/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
"ForStatement WhileStatement": cx => /^\s*else:/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
TryStatement: cx => /^\s*(except |finally:|else:)/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression": delimitedIndent({closing: ")"}),
"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression": delimitedIndent({closing: "}"}),
Expand Down

0 comments on commit 0cf3593

Please sign in to comment.