[Python-bugs-list] [ python-Bugs-587239 ] python-mode and nested indents

noreply@sourceforge.net noreply@sourceforge.net
Fri, 26 Jul 2002 14:49:47 -0700


Bugs item #587239, was opened at 2002-07-26 20:56
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=587239&group_id=5470

Category: Demos and Tools
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Andrew Koenig (arkoenig)
Assigned to: Nobody/Anonymous (nobody)
Summary: python-mode and nested indents

Initial Comment:
Using Python-mode 4.6 and GNU emacs 21.2.2, I enter the
following:

if x < 0:
    for i in range(100):
        print i
else:
    print "x is negative"

If I now put the cursor on the "else:" line and hit
tab, it erroneously changes the indentation to line the
"else" up with the "for" above it.


----------------------------------------------------------------------

>Comment By: Andrew Koenig (arkoenig)
Date: 2002-07-26 21:49

Message:
Logged In: YES 
user_id=418174

Frankly, I hadn't thought of that possibility!

However, I still consider the behavior a bug, for two
reasons:  (1) I can type something that's syntactically
valid, hit tab, and have it change the meaning of what I
typed, and (2) It changes the indentation in the same way if
I say "elif:" instead of "else:", even though that change is
not syntactically valid.  That is (using -> to indicate a
tab):

if x < 0:
->for i in range(100):
->->print i
elif x > 0:
->print x

Again, hitting tab on the "elif" line will indent the "elif"
to line up with the "for", even though the result is
syntactically invalid.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-07-26 21:14

Message:
Logged In: YES 
user_id=31435

Andrew, why is that erroneous?  Loops in Python have 
(optional) "else:" clauses too.  There's no way for pymode to 
guess whether you intended the else to go with the if or the 
for.  I expect it looks backward for the closest-preceding 
construct the else-statement could "belong to", and finds 
the for-loop first.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=587239&group_id=5470