Newline honor dedent

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

Bug Description

Is possible to make the cursor remember the indention which has been set in the "blank/whitespace only" line when moving to a next line?

Here are the steps to replicate the problem:

if condition: # first line
    if condition_2: # second line
        do_something() # third line and i press RET
    2 1 # the cursor appears in position 1, then I press backspace and it goes to 2, finally I press RET
    4 3 # after the previous RET the cursor goes to position marked by 3, but i would like it to stay in column
             # defined in previous line by last position and appear on the position marked by 4

I would like the cursor to go from position 2 directly to 4 when RET is pressed.

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

If py-newline-and-indent is called from an empty but dedented line, don't go to the outmost indent, honor dedent.

Changed in python-mode:
importance: Undecided → Medium
status: New → In Progress
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.1.4
Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
lukas (fossrox) wrote :

Thank you very much, this seems to solve the problem when indent is decreased manually.

I only wonder if newline should honor as well absence of any indent in an empty line, that is of course in case when the user removes all the indent on an empty line and then presses return? Currently the cursor would be moved again to the outmost indent.

Additionally, probably there is a little typo in the name py--delete-trailing-whitepace -- should it be py--delete-trailing-whitespace?

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 1280982] Re: Newline honor dedent

Am 17.02.2014 13:51, schrieb lukas:
> Thank you very much, this seems to solve the problem when indent is
> decreased manually.
>
> I only wonder if newline should honor as well absence of any indent in
> an empty line, that is of course in case when the user removes all the
> indent on an empty line and then presses return? Currently the cursor
> would be moved again to the outmost indent.
>

Thanks, see there is something left. Also if last command was a indent a certain pos, probably that should be honored.

> Additionally, probably there is a little typo in the name py--delete-
> trailing-whitepace -- should it be py--delete-trailing-whitespace?
>

Yes, will fix it.

Changed in python-mode:
status: Fix Committed → In Progress
Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
lukas (fossrox) wrote :

Thank you very much! The dedent now works great. But just noticed one thing which would require a fix probably in this place.

Whenever there is an empty line after a block of code - let's say for the reproduction purpose: the last line in the block has 4 levels of indention - and the user introduces an indent different in the empty line following the block and presses RET, the point is moved to a new line and again moved to the outmost indent. This does not seem being disruptive and might be even desired, but it gets under a question as a consequence in this case:

[0] let's start from beginning

[1] after a line with an indent n, there is a "second" non empty line with indent m < n

[2] the "second" line can be preceded by any amount of empty lines (zero or hundred empty lines included)

[3] the user places the point at the beginning of the "second" line or on the first non whitespace character in the "second" line and presses RET

[4] again the point is moved to next line and to the outmost indent, with the whole text following the cursor (***) -- I think that in such a situation the desired behavior would be to just move the text to next line with point and first char of the text placed precisely in the same column

*** if the point has been placed on the beginning of the "second" line, and not on the first non whitespace character, that is when there was a whitespace between the point and the following first non whitespace character of the "second" line, after pressing RET, the following text not only will be moved to the outmost indent on next line, but it will be moved with all the additional whitespace in front of it, resulting in even more increased indent

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

Am 18.02.2014 16:34, schrieb lukas:
> Thank you very much! The dedent now works great. But just noticed one
> thing which would require a fix probably in this place.
>
> Whenever there is an empty line after a block of code - let's say for
> the reproduction purpose: the last line in the block has 4 levels of
> indention - and the user introduces an indent different in the empty
> line following the block and presses RET, the point is moved to a new
> line and again moved to the outmost indent.

That would mean a bug.
Implementation is now: if user indents an empty line deliberately, this indent shall be honored by a following py-newline-and-indent.

May you send some example code, which triggers the bug?

Revision history for this message
lukas (fossrox) wrote :

Linking to colored version as it might provide a better overview:
http://paste.debian.net/82756/

Hope this helps :)

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

Am 18.02.2014 19:08, schrieb lukas:
> Linking to colored version as it might provide a better overview:
> http://paste.debian.net/82756/
>
> Hope this helps :)
>

Hmm, the new feature will take action only, if a dedent command precedes.
If you just jump onto some spot which is indented already, it indents outmost.

Might be reasonable to cancel the limitation, will re-open.

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

Related questions

Remote bug watches

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