python-mode loops on if/else

Bug #328777 reported by Montanaro
2
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

(migrating from python project)

Original submission:

Here's how to reproduce. Create a .py file in XEmacs
 containing this text:

 x = (if 1: 2
  ____else: 3)

 (except that the ____ really means four spaces).

 Now position your cursor somewhere inside those 4
 spaces, and hit TAB. XEmacs freezes until you hit
^G.

Followup comments:

Date: 2003-07-31 22:41
Sender: montanaro
Logged In: YES
user_id=44345

The code gets into an infloop in py-outdent-p. The
loop looks
odd to me:

  (while (or (looking-at py-blank-or-comment-re)
                (bobp))
     (backward-to-indentation 1))

If you were at (bobp), why would you want to try to
move back
a line?

[http://sourceforge.net/tracker/index.php?func=detail&aid=783240&group_id=86916&atid=581349]

Related branches

Revision history for this message
Mark-byers (mark-byers) wrote :

I can confirm this bug.

The following two line file also causes an infinite loop:

a
else:

When the colon is typed, the inifinite loop is triggered.

I think the following change fixes the problem:

- (while (or (looking-at py-blank-or-comment-re)
- (bobp))
+ (while (and (looking-at py-blank-or-comment-re)
+ (not (bobp)))
                  (backward-to-indentation 1))

Revision history for this message
Mark-byers (mark-byers) wrote :

Here is a patch file. I wasn't sure how to attach it as a
file, so here it is in plain text. It seems that the 'short
circuit infloop on illegal construct' line is no longer
needed so I have removed it.

--- python-mode/python-mode.el 2005-02-20 14:23:58.000000000
+0100
+++ python-mode/python-mode.el.new 2005-02-20
14:29:05.319602112 +0100
@@ -1239,13 +1239,11 @@
   (save-excursion
     (and (progn (back-to-indentation)
   (looking-at py-outdent-re))
- ;; short circuit infloop on illegal construct
- (not (bobp))
   (progn (forward-line -1)
   (py-goto-initial-line)
   (back-to-indentation)
- (while (or (looking-at py-blank-or-comment-re)
- (bobp))
+ (while (and (looking-at py-blank-or-comment-re)
+ (not (bobp)))
     (backward-to-indentation 1))
   (not (looking-at py-no-outdent-re)))
   )))

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi Skip,

get an syntax-errror

   File "<ipython console>", line 1
     x = (if 1: 2)
           ^
SyntaxError: invalid syntax

###########

When changing the form all is fine.
Do you still experience a freeze from TAB?

Andreas

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi,

as the form pointed at looks insane in any case, will change that.

Thanks

Andreas

Changed in python-mode:
status: New → Fix Committed
Changed in python-mode:
milestone: none → 6.0
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.