Skip to content

Conversation

smitbarmase
Copy link
Member

@smitbarmase smitbarmase commented Jun 25, 2025

Closes #33238, follow-up to #29625.

Changes:

  • Removed significant_indentation, which was the way to introduce indentation scoping in languages like Python. However, it turned out to be unnecessarily complicated to define and maintain.
  • Introduced decrease_indent_patterns, which takes a pattern keyword to automatically outdent and valid_after keywords to treat as valid code points to snap to. The outdent happens to the most recent valid_after keyword that also has less or equal indentation than the currently typed keyword.

Fixes:

  1. In Python, typing except, finally, else, and so on now automatically indents intelligently based on the context in which it appears. For instance:
try:
    if a == 1:
        try:
             b = 2
             ^  # <-- typing "except:" here would indent it to inner try block

but,

try:
    if a == 1:
        try:
             b = 2
    ^  # <-- typing "except:" here would indent it to outer try block
  1. Fixes comments not maintaining indent.

Release Notes:

  • Improved auto outdent for Python while typing keywords like except, else, finally, etc.
  • Fixed the issue where comments in Python would not maintain their indentation.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jun 25, 2025
@smitbarmase smitbarmase force-pushed the improve-indent-python branch from 94ac38b to 763c138 Compare June 26, 2025 05:21
@smitbarmase smitbarmase merged commit d09c7eb into main Jun 26, 2025
21 checks passed
@smitbarmase smitbarmase deleted the improve-indent-python branch June 26, 2025 05:41
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jun 28, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 4, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
aviatesk added a commit to aviatesk/zed-julia that referenced this pull request Jul 4, 2025
This commit adds both regex-based and Tree-sitter-based indentation
rules to provide a smooth editing experience for Julia coding in Zed.

Motivation - this didn't work properly before:
```julia
if x
elseif y
    else    # <- wouldn't auto-outdent
end
```

Changes:
- Add `increase_indent_pattern` for Julia block keywords
- Add `decrease_indent_patterns` with context-aware `valid_after` rules
- Add `@start.suffix` captures in indents.scm for tracking block beginnings
  (required for `decrease_indent_patterns` to be functional)
- Update `@outdent` patterns to work with specific keywords

The dual approach (regex + Tree-sitter) is intentional, following Zed's
design pattern established for Python (see zed-industries/zed#29625,
zed-industries/zed#33370).
smitbarmase added a commit that referenced this pull request Jul 7, 2025
Closes #34002

`decrease_indent_patterns` should only contain mapping which are at same
indent level with each other, which is not true for `match` and `case`
mapping.

Caused in #33370

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python: Only comment in if statement auto outdents it
1 participant