Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit 0cf3593

Browse files
committed
Improve indentation of else line under for/while loops
FIX: Properly indent `else:` when attached to a `for` or `while` statement. Closes codemirror/dev#1363
1 parent ce4804b commit 0cf3593

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/python.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const pythonLanguage = LRLanguage.define({
3333
indentNodeProp.add({
3434
Body: context => indentBody(context, context.node) ?? context.continue(),
3535
IfStatement: cx => /^\s*(else:|elif )/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
36+
"ForStatement WhileStatement": cx => /^\s*else:/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
3637
TryStatement: cx => /^\s*(except |finally:|else:)/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
3738
"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression": delimitedIndent({closing: ")"}),
3839
"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression": delimitedIndent({closing: "}"}),

0 commit comments

Comments
 (0)