Bug 392732 - python (unnecessary) automatic indentation
Summary: python (unnecessary) automatic indentation
Status: RESOLVED FIXED
Alias: None
Product: frameworks-ktexteditor
Classification: Frameworks and Libraries
Component: indentation (show other bugs)
Version: 5.58.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-04 16:35 UTC by f3046011
Modified: 2021-08-29 09:19 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description f3046011 2018-04-04 16:35:38 UTC
while 1:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
        elif event.type == KEYDOWN:
            if event.key == K_LEFT:
                xvel = 1
            elif event.key == K_RIGHT:
                xvel = -1
            elif event.key == K_UP:
                yvel = 1
            elif event.key == K_DOWN:
                yvel = -1
        |1      |2

This is some code in python using pygame. "|1" and "|2" represents the locations where I'm experiencing the issue (They are not really in the code). If I want to type in another "elif" when the cursor is at |1 it automatically indents what im typing to |2. This also seems to happen in other cases with the same "scenario". I wrote a similar program before on a different computer using kubuntu 17.10 and kate 17.04.3 where this didn't happen ever. 
I expect automatic indentation when making a new line after a colon but not in cases like this one. I can get annoying when writing code with a lot of different indentation levels.
Comment 1 Karthik Periagaram 2019-05-26 06:29:17 UTC
Confirmed using latest packages on Arch linux (Frameworks 5.58.0, Qt 5.12.3, Kwrite 19.04.1). Updating version to indicate this.

Automatic indentation seems to be broken for python if/elif/else. Here is a simpler example to demonstrate this behavior:

(. = space, | = cursor, indentation set to using spaces, indent level 4 spaces)

def main():
....if True:
........main()|

Press enter and start elif block

def main():
....if True:
........main()
........elif False:|

Upon typing `:`, the indentation of the elif line should have been reduced. Instead, when I press enter, I get,

def main():
....if True:
........main()
........elif False:
............|

This behavior also happens for else.
Comment 2 Christoph Cullmann 2021-08-29 09:19:38 UTC
Git commit b5895aa27b9b9fe8cb7408a65fa9f1c35fcb1da5 by Christoph Cullmann, on behalf of Ilia Kats.
Committed on 29/08/2021 at 09:19.
Pushed by cullmann into branch 'master'.

Python indentation: decrease indent when appropriate keyword is typed

A  +3    -0    autotests/input/indent/python/dedentElif1/expected
A  +3    -0    autotests/input/indent/python/dedentElif1/input.js
A  +2    -0    autotests/input/indent/python/dedentElif1/origin
A  +3    -0    autotests/input/indent/python/dedentElif2/expected
A  +3    -0    autotests/input/indent/python/dedentElif2/input.js
A  +2    -0    autotests/input/indent/python/dedentElif2/origin
A  +3    -0    autotests/input/indent/python/dedentElse1/expected
A  +3    -0    autotests/input/indent/python/dedentElse1/input.js
A  +2    -0    autotests/input/indent/python/dedentElse1/origin
A  +3    -0    autotests/input/indent/python/dedentElse2/expected
A  +3    -0    autotests/input/indent/python/dedentElse2/input.js
A  +2    -0    autotests/input/indent/python/dedentElse2/origin
A  +7    -0    autotests/input/indent/python/dedentElse3/expected
A  +3    -0    autotests/input/indent/python/dedentElse3/input.js
A  +6    -0    autotests/input/indent/python/dedentElse3/origin
A  +6    -0    autotests/input/indent/python/dedentElse4/expected
A  +3    -0    autotests/input/indent/python/dedentElse4/input.js
A  +4    -0    autotests/input/indent/python/dedentElse4/origin
A  +6    -0    autotests/input/indent/python/dedentElse5/expected
A  +3    -0    autotests/input/indent/python/dedentElse5/input.js
A  +5    -0    autotests/input/indent/python/dedentElse5/origin
A  +3    -0    autotests/input/indent/python/dedentElse6/expected
A  +3    -0    autotests/input/indent/python/dedentElse6/input.js
A  +2    -0    autotests/input/indent/python/dedentElse6/origin
A  +3    -0    autotests/input/indent/python/dedentExcept1/expected
A  +3    -0    autotests/input/indent/python/dedentExcept1/input.js
A  +2    -0    autotests/input/indent/python/dedentExcept1/origin
A  +3    -0    autotests/input/indent/python/dedentExcept2/expected
A  +3    -0    autotests/input/indent/python/dedentExcept2/input.js
A  +2    -0    autotests/input/indent/python/dedentExcept2/origin
A  +3    -0    autotests/input/indent/python/dedentFinally1/expected
A  +3    -0    autotests/input/indent/python/dedentFinally1/input.js
A  +2    -0    autotests/input/indent/python/dedentFinally1/origin
A  +3    -0    autotests/input/indent/python/dedentFinally2/expected
A  +3    -0    autotests/input/indent/python/dedentFinally2/input.js
A  +2    -0    autotests/input/indent/python/dedentFinally2/origin
M  +34   -10   src/script/data/indentation/python.js

https://invent.kde.org/frameworks/ktexteditor/commit/b5895aa27b9b9fe8cb7408a65fa9f1c35fcb1da5