Return statements are sometimes indented incorrectly.

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

Bug Description

Return statements are sometimes indented incorrectly.

For example, if I enter the following code and press TAB with the cursor on
the 'return' line, the return statement is indented two steps, to align with
'bar()'. It should be indented only one step, to align with 'baz()'.

def foo():
    while True:
        bar()
    baz()
return 1

Observed with python-mode 6.0.10, emacs versions 23.4 and 24.1, with all
default configuration variables.

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 1019601] [NEW] Return statements are sometimes indented incorrectly.

Am 30.06.2012 16:36, schrieb Matthew Woodcraft:
> Public bug reported:
>
> Return statements are sometimes indented incorrectly.
>
> For example, if I enter the following code and press TAB with the cursor on
> the 'return' line, the return statement is indented two steps, to align with
> 'bar()'. It should be indented only one step, to align with 'baz()'.

Hi,

thanks for the report.

When cursor is behind baz()

C-j --M-x py-newline-and-and-indent-- should reach col 4, right?

Than insert "return 1"

Question: which command caused the dedent?

Andreas

>
> def foo():
> while True:
> bar()
> baz()
> return 1
>
> Observed with python-mode 6.0.10, emacs versions 23.4 and 24.1, with all
> default configuration variables.
>
> ** Affects: python-mode
> Importance: Undecided
> Status: New
>

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

Am 30.06.2012 16:36, schrieb Matthew Woodcraft:
> Public bug reported:
>
> Return statements are sometimes indented incorrectly.
>
> For example, if I enter the following code and press TAB with the cursor on
> the 'return' line, the return statement is indented two steps, to align with
> 'bar()'. It should be indented only one step, to align with 'baz()'.
>
> def foo():
> while True:
> bar()
> baz()
> return 1
>
> Observed with python-mode 6.0.10, emacs versions 23.4 and 24.1, with all
> default configuration variables.
>

okay, see you answered my question already.

See docstring of py-indent-line for the way TAB works
i.e. it circles the permitted indents.

IMO it's not a bug.

Should you have difficulties with it's usage resp. want a different behavior, don't hesitate to ask here.

Andreas

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
importance: Undecided → Medium
milestone: none → 6.1.0
Revision history for this message
Matthew Woodcraft (nhdl-matthew-8d0z) wrote :

Andreas Roehler wrote:
> When cursor is behind baz()
>
> C-j --M-x py-newline-and-and-indent-- should reach col 4, right?

Yes, that's what I get.

> Than insert "return 1"
>
> Question: which command caused the dedent?

That was an artificial example to show the bug clearly.

In practice the most annoying situation for me is this one:

def foo():
    while True:
        bar()
    baz()
    return 1

I have the cursor at the start of the line containing 'return' and press RET
(py-newline-and-indent) to add a new line after baz(), and it indents the
return:

def foo():
    while True:
        bar()
    baz()

        return 1

This doesn't happen if the line being moved down is something other than a
return statement.

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

Am 30.06.2012 20:02, schrieb Matthew Woodcraft:
> Andreas Roehler wrote:
>> When cursor is behind baz()
>>
>> C-j --M-x py-newline-and-and-indent-- should reach col 4, right?
>
> Yes, that's what I get.
>
>> Than insert "return 1"
>>
>> Question: which command caused the dedent?
>
> That was an artificial example to show the bug clearly.
>
> In practice the most annoying situation for me is this one:
>
> def foo():
> while True:
> bar()
> baz()
> return 1
>
> I have the cursor at the start of the line containing 'return' and press RET
> (py-newline-and-indent) to add a new line after baz(), and it indents the
> return:
>
> def foo():
> while True:
> bar()
> baz()
>
> return 1
>
> This doesn't happen if the line being moved down is something other than a
> return statement.
>

hmm, can't get it. Attach you a png displaying after RET - from behind baz()

Maybe send the output of M-x report-emacs-bug

Revision history for this message
Matthew Woodcraft (nhdl-matthew-8d0z) wrote :

Andreas Roehler wrote:
> hmm, can't get it. Attach you a png displaying after RET - from behind baz()

Yes, it's OK if I press RET from after baz().

The problem occurs if I press RET with the cursor at either the start of the
line containing return, or immediately before the 'r' of return.

It's also OK if I use C-o (open-line) instead of RET, but it turns out that
this is not what my fingers are used to doing.

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

Am 30.06.2012 20:57, schrieb Matthew Woodcraft:
> Andreas Roehler wrote:
>> hmm, can't get it. Attach you a png displaying after RET - from behind baz()
>
> Yes, it's OK if I press RET from after baz().
>
> The problem occurs if I press RET with the cursor at either the start of the
> line containing return,

okay, see it, that's a bug, thanks

  or immediately before the 'r' of return.
>
> It's also OK if I use C-o (open-line) instead of RET, but it turns out that
> this is not what my fingers are used to doing.
>

Changed in python-mode:
status: New → Confirmed
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 30.06.2012 20:57, schrieb Matthew Woodcraft:

fixed in trunk

may you check out and try again?

thx

Changed in python-mode:
status: Confirmed → Fix Committed
Revision history for this message
Matthew Woodcraft (nhdl-matthew-8d0z) wrote :

Andreas Roehler wrote:
> fixed in trunk
>
> may you check out and try again?

Yes, I can confirm that is fixed. Thank you very much.

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

Bug attachments

Remote bug watches

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