Bug 356241 - Python indenter should not keep indentation level following complete class/function definitions with blank lines in between
Summary: Python indenter should not keep indentation level following complete class/fu...
Status: REPORTED
Alias: None
Product: frameworks-ktexteditor
Classification: Frameworks and Libraries
Component: indentation (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL: http://pastebin.com/v7rUJZTJ
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-03 12:07 UTC by Thomas Kolar
Modified: 2021-10-04 22:01 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Kolar 2015-12-03 12:07:47 UTC
At the moment, creating a new line anywhere in a python script where the last non-blank line is indented (and not a dedenter) will always indent that line to the previous indentation level.

While this may have been indented (as was this pun), it is VERY annoying for editing files with many small class definitions. Not all code blocks have a natural dedenter; and as a matter of fact, if one follows pep8, most of the time, if there is more than one blank line between two lines, the second line will not be indented at all. See also: https://www.python.org/dev/peps/pep-0008/#blank-lines

In this light, assuming that the user wants to continue at the same indentation level as a block many lines previous is likely a bug.

Reproducible: Always

Steps to Reproduce:
1. Open a new file, save as a python script
2. Enter the following:
"""
class Example(object):
    def example_method(self)
        self.mutate() # no return required


"""
3. With the cursor on the last line, type <enter>

Actual Results:  
two levels of indentation are inserted

Expected Results:  
insert no indentation, that method is too far away

I like Kate a lot and have been using it for years, it's my go-to editor when I have multiple files that i switch between a lot, but this is seriously annoying me, and I can't imagine that most people find this behaviour more useful than annoying.

I crudely patched my own indenter and linked the diff, however, I can imagine that there are probably better solutions (my patch checks if the two previous lines are completely empty).