# language: Add context-aware decrease indent for Python \(\#33370\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/d09c7eb317af707fb15ba4a072a4c4288e5931ad)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: d09c7eb317af707fb15ba4a072a4c4288e5931ad

Requested commit: d09c7eb317af707fb15ba4a072a4c4288e5931ad

Commit: d09c7eb317af707fb15ba4a072a4c4288e5931ad

Tree: 005e761f0a79e3d04c5e71f1522bb38965540d27

Author: Smit Barmase

Committer: GitHub

## Message

````
language: Add context-aware decrease indent for Python (#33370)

Closes #33238, follow-up to
https://github.com/zed-industries/zed/pull/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:

```py
try:
    if a == 1:
        try:
             b = 2
             ^  # <-- typing "except:" here would indent it to inner try block
```

but,

```py
try:
    if a == 1:
        try:
             b = 2
    ^  # <-- typing "except:" here would indent it to outer try block
```

2. 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.
````

## Parents

- [175343240675a820c63dd57b77bf796a089e646d](https://git.cafe/gitcafe/zed/commit/175343240675a820c63dd57b77bf796a089e646d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/d09c7eb317af707fb15ba4a072a4c4288e5931ad?format=markdown)
