py-guess-indent-offset does not work

Bug #902893 reported by Peter Milliken
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

When running py-guess-indent-offset manually it "guesses" incorrectly depending on where point is on invocation i.e. the following code (which has an indent of 2) "guesses" a value of 6 when point is at the indicated position:

def gather (port):
  """{text}"""
  result = []
  # wait until the AP has started transmitting...
  while port.inWaiting() < 10:
    pass

  now = time.time()
  while True:
    if port.inWaiting() > 0:
      while port.inWaiting() > 0:
        result.append(port.read(1))

      now = time.time()
    else:
      if (time.time() - now) > 10.0:
        break ^ point is here when py-guess-indent-offset is run

  return result

With this same def, depending on where point is at the time py-guess-indent-offset is run, I can get values of 2, 4 or 6.

Thanks
Peter

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.0.4
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Andreas Roehler (a-roehler) wrote :

could you check again?

thanks,

Andreas

Revision history for this message
Peter Milliken (peter-milliken) wrote :

Sorry, it appears to be worse.

I download latest python-mode.el (only this file) and get the following error message in Emacs:

Wrong number of arguments: (lambda nil (and (>= guessed 2) (<= guessed 8) (eq 0 (% guessed 2)))), 1

I traced it to running line 1444:

        (if (py-guessed-sanity-check guessed)

Unfortunately, py-guess-indent-offset is also called when executing py-newline-and-indent (giving the same error), so this python-mode.el is unusable.

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 902893] Re: py-guess-indent-offset does not work

Am 12.12.2011 20:38, schrieb Peter Milliken:
> Sorry, it appears to be worse.
>
> I download latest python-mode.el (only this file) and get the following
> error message in Emacs:
>
> Wrong number of arguments: (lambda nil (and (>= guessed 2) (<= guessed
> 8) (eq 0 (% guessed 2)))), 1
>
> I traced it to running line 1444:
>
> (if (py-guessed-sanity-check guessed)
>
> Unfortunately, py-guess-indent-offset is also called when executing py-
> newline-and-indent (giving the same error), so this python-mode.el is
> unusable.
>

checked in a fix

let's see if we are luckier today

Changed in python-mode:
status: Confirmed → Fix Committed
Revision history for this message
Peter Milliken (peter-milliken) wrote :

Still doesn't work.

It still provides differing values depending on where point is at the time it is run i.e. sometimes 2, sometimes 4.

Also, because py-guess-indent-offset is called whilst running py-newline-and-indent, the "correct" value gets clobbered even after it gets "set" correctly :-(

Changed in python-mode:
status: Fix Committed → In Progress
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 13.12.2011 19:55, schrieb Peter Milliken:
> Still doesn't work.
>
> It still provides differing values depending on where point is at the
> time it is run i.e. sometimes 2, sometimes 4.

there was a bug still which caused alternating.

maybe done now?

>
> Also, because py-guess-indent-offset is called whilst running py-
> newline-and-indent,

if py-smart-indentation is in use, that must be done basically.

the "correct" value gets clobbered even after it
> gets "set" correctly :-(
>

that's too bad indeed. Let's head toward better times :)

Revision history for this message
Peter Milliken (peter-milliken) wrote :

That one seems to have nailed it - thanks! :-)

The indentation is being correctly set when Emacs loads the .py file as well!.

Great work :-)

Changed in python-mode:
status: In Progress → Fix Committed
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.