Menu

#3 python-mode loops on if/else

open
nobody
None
5
2003-08-05
2003-08-05
No

(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?

Discussion

  • Mark Byers

    Mark Byers - 2005-02-20

    Logged In: YES
    user_id=1223583

    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))

     
  • Mark Byers

    Mark Byers - 2005-02-20

    Logged In: YES
    user_id=1223583

    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)))
    )))

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.