https://bugs.kde.org/show_bug.cgi?id=518196
Bug ID: 518196
Summary: Python snippets do not un-indent properly
Classification: Applications
Product: kate
Version First 23.08.5
Reported In:
Platform: Kubuntu
OS: Linux
Status: REPORTED
Severity: normal
Priority: NOR
Component: plugin-snippets
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
SUMMARY
Snippets in Python with indentations behave poorly with auto-indent settings.
This is different between the snippets tester sub-window and the real document.
STEPS TO REPRODUCE
1. Create a file with Python formatting (e.g. by saving a file with a .py
extension)
2. Create a snippet which has indents and un-indents. Like this one:
```
def test(a, b):
if a:
if b:
print(a)
print(b)
return
```
3. Test snippet in the snippet editor to a satisfying result.
4. Return to file with Python formatting and insert the snippet.
OBSERVED RESULT
The inserted snippet looks like the following:
```
def test(a, b):
if a:
if b:
print(a)
print(b)
return
```
This function will fail to print the correct line at the correct time, and it
will generate an error since it does not return properly.
EXPECTED RESULT
If we do the same steps with a C-like file and C-like snippet, everything works
fine. Using the following C++ snippet, I have no problem inserting with
correct indentation:
```
void test(int a, int b) {
if (a > 1) {
if (b > 1) {
std::cout << b << std::endl;
}
std::cout << a << std::endl;
}
}
```
The problem seems to be on the Kate side, not the Snippet side. If you do
something silly like insert the C++ snippet into a document with Python typing,
the indents fail in a similar manner to the Python-Python instance.
I have not found a setting which changes this behavior. Deselecting
indentation types for Python files in settings appears to have no effect. I
would be happy to be proven wrong on this.
LITTLE TRICKS
The Python snippet behaves correctly if you include a jump statement. The
following snippet works correctly
```
def test(a, b):
if a:
if b:
print(a)
pass
print(b)
pass
return
```
Using the NOP jump statement ``pass`` here does nothing detrimental to your
code and unindents correctly. However, this is not very PEP, and can create a
real ugly mess once your snippets start getting 100+ lines.
SOFTWARE/OS VERSIONS
Operating System: Kubuntu 24.04
KDE Plasma Version: 5.27.12
KDE Frameworks Version: 5.115.0
Qt Version: 5.15.13
Kernel Version: 6.8.0-90-generic (64-bit)
Graphics Platform: offscreen
Processors: 16 × AMD Ryzen 9 5900HX with Radeon Graphics
Memory: 62.2 GiB of RAM
Graphics Processor: AMD Radeon Graphics
ADDITIONAL INFORMATION
--
You are receiving this mail because:
You are watching all bug changes.