mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-30 20:40:04 +01:00
d09c7eb317
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.
39 lines
2.4 KiB
TOML
39 lines
2.4 KiB
TOML
name = "Python"
|
|
grammar = "python"
|
|
path_suffixes = ["py", "pyi", "mpy"]
|
|
first_line_pattern = '^#!.*\bpython[0-9.]*\b'
|
|
line_comments = ["# "]
|
|
autoclose_before = ";:.,=}])>"
|
|
brackets = [
|
|
{ start = "f\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "f'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "b\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "b'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "u\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "u'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "r\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "r'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "rb\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "rb'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "t\"", end = "\"", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "t'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "\"\"\"", end = "\"\"\"", close = true, newline = false, not_in = ["string"] },
|
|
{ start = "'''", end = "'''", close = true, newline = false, not_in = ["string"] },
|
|
{ start = "{", end = "}", close = true, newline = true },
|
|
{ start = "[", end = "]", close = true, newline = true },
|
|
{ start = "(", end = ")", close = true, newline = true },
|
|
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
|
|
{ start = "'", end = "'", close = true, newline = false, not_in = ["string"] },
|
|
]
|
|
|
|
auto_indent_using_last_non_empty_line = false
|
|
debuggers = ["Debugpy"]
|
|
increase_indent_pattern = "^[^#].*:\\s*$"
|
|
decrease_indent_patterns = [
|
|
{ pattern = "^\\s*elif\\b.*:", valid_after = ["if", "elif"] },
|
|
{ pattern = "^\\s*else\\b.*:", valid_after = ["if", "elif", "for", "while", "except"] },
|
|
{ pattern = "^\\s*except\\b.*:", valid_after = ["try", "except"] },
|
|
{ pattern = "^\\s*finally\\b.*:", valid_after = ["try", "except", "else"] },
|
|
{ pattern = "^\\s*case\\b.*:", valid_after = ["match", "case"] }
|
|
]
|