Author Topic: Python...  (Read 2494 times)

jporkkahtc

  • Senior Community Member
  • Posts: 1895
  • Hero Points: 184
  • Text
Python...
« on: October 30, 2013, 06:10:16 pm »
When try to write Python code its hard to get the indenting correct as there is no close-brace to tell Slick when to stop indenting.

When at the end of a block, how do I get slick to stop indenting to the level of the block?
For example:
Code: [Select]
if blah:
    doSomething() 
 else:
    otherWise()

moreCode()

When I put the cursor at Col#1 of "moreCode" and hit enter, Slick inserts a line and indents moreCode().
When I put the cursor at Col#1 of "moreCode" and hit TAB, Slick indents moreCode() and moves the cursor to Col#9.
(I have "home" configured to goto Col#1).
If the cursor is at the "m" of "moreCode" and hit enter, then Slick just inserts a line.
 
Similar problem - when entering code like the above, how do you un-indent at the end of a block?
Place the cursor at the EOL of the "otherWise()" line.
Hit <enter> <shift+tab> <enter> and then type "moreCode".
Note that "moreCode" is indented to the same level as "otherWise()" - because hitting <enter> the second time to add a blank line makes Slick indent to the level of the previous block.
 
 
Working with Python with multiple levels of indent is even worse - say in a function with 4 or 5 levels of nesting.
 
Any tips or tricks to making this work better?

Matthew

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 990
  • Hero Points: 44
Re: Python...
« Reply #1 on: October 31, 2013, 05:33:42 pm »
Since there are no other hints, like close braces, the only thing we can be guided by is the indent level of the preceding code lines (which are non-empty). There's a behavior going on here that you may not be aware of.
To wit:
Using your example, at the end of the otherwise() line, hit <Enter> twice. You'll get the blank line, yet the cursor will still be at the start of otherwise(), in column 5. Now press Shift+Tab to unindent, and you'll be back at col #1. Type moreCode() and press <Enter>.
Now the strange part is that you may be thinking that not pressing Shift+Tab (to get to col #1) in the blank separator line means that there are now 4 extraneous spaces in that blank line. But there aren't. They've been stripped out. If you look at this in hex view you'll see that there are only line-break sequences between the end of otherwise() and the start of moreCode().
So the bottom line is that once you've done a Shift+Tab to unindent, only the presence of non-blank text will make that indent "take".