8000 Improve indentation of else line under for/while loops · codemirror/lang-python@0cf3593 · GitHub
[go: up one dir, main page]

Skip to content

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

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

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)
0