Author Topic: Python editing / indenting  (Read 1820 times)

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Python editing / indenting
« on: April 28, 2022, 06:52:11 PM »
When editing Python Slickedit likes to indent too much.
For functions at least, I can always include an empty return or pass statement, but for blocks inside of a function that doesn't work as well.

#1 I'd like to have an option to outdent when I enter a blank line inside of a block. (its arguable if that means 1 or 2 blank lines I suppose).
#2 Python should automatically outdent for nested def or class. Sure, the language allows these to be nested, but it is far more common not to do so.


For example, given this:
Code: [Select]
def one():
    print("Hey")

if I select that and then paste it at the end, I get:
Code: [Select]
def one():
    print("Hey")

    def one():
        print("Hey")
Which is almost never the right thing to do.

Same thing while typing, it only outdents after certain words (return, raise, etc)
It might be nice while typing (not beautifying!) that an extra blank line will outdent.
Then if I type this (without manually outdenting for "two"):
Code: [Select]
def one():
    print("Hey")

    def two():
        print("there")
Instead I would get
Code: [Select]
def one():
    print("Hey")

def two():
    print("there")


Inside of a function, with if statements, currently I get this:
Code: [Select]
    if is_true:
        print("True")

        if is_false:
            print("False"):
But, I would like to get this (without manually outdenting for the 2nd if):
Code: [Select]
    if is_true:
        print("True")

    if is_false:
        print("False"):


Not having block delimiters was supposed to make Python simpler, but in reality it just complicates things!

JeffB

  • Senior Community Member
  • Posts: 326
  • Hero Points: 14
Re: Python editing / indenting
« Reply #1 on: May 31, 2022, 03:05:26 PM »
+1 for this. I never narrowed down exactly what makes slickedit decide when or not to indent, but it's wrong (for me) about 90% of the time.  "undo" helps sometimes to just re-unindent, but pasting Python code in slickedit is a pain :(