How to preserve indent set in previous "blank" line?

Asked by lukas

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.

Question information

Language:
English Edit question
Status:
Solved
For:
python-mode.el Edit question
Assignee:
No assignee Edit question
Solved by:
Andreas Roehler
Solved:
Last query:
Last reply:
Revision history for this message
lukas (fossrox) said :
#1

There is a variable 'py-empty-line-closes-p' which allows with RET apply one dedent after an empty line (result is identical like calling py-newline-and-dedent) but is not really helpful in cases with more indents.

Something like py-newline-and-keep-indent maybe would need to be implemented?

Revision history for this message
Andreas Roehler (a-roehler) said :
#2

Am 16.02.2014 15:01, schrieb lukas:
> Question #244068 on python-mode.el changed:
> https://answers.launchpad.net/python-mode/+question/244068
>
> Description changed to:
> 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.
>

Being afraid don't understand well.
Please tell again with a single example: pos previous, after and which command in use.

Maybe C-j does it for you?

Revision history for this message
lukas (fossrox) said :
#3

I believe the description might be confusing due to launchpad removing some of the white spaces, using non monospace font and wrapping text, as it looks especially in the quote attached to your message.

Please instead check this paste http://paste.debian.net/plain/82417

The numbers mark positions where the cursors (point) is placed in the order:

hit RET at the end on the 3rd line ---> moves cursor to the position marked by 1 on the 4th line

then hit BACKSPACE on the 4th line ---> cursor goes to position marked by number 2 on the 4th line

hit RET when cursor on position marked by number 2 ---> cursor goes to position marked by number 3 on the 5th line

then again hit BACKSPACE ---> cursor goes to position marked by number 4 on the 5th line

How to make the cursor move 1-2-4 instead of the current 1-2-3-4?
How to make it stay in column of numbers 2, 4 instead of jumping on every next press of RET back to the column with numbers 1,3?

The numbers 1, 2, 3, 4 of are not a part of the code. I placed them in text only to mark the positions of the cursor/point. Hope this all make it clearer.

Answering your question:
C-j calls the command py-new-line-and-indent so it results exactly in the same behavior i describe above, which i would like to alter.

Revision history for this message
Best Andreas Roehler (a-roehler) said :
#4

Am 16.02.2014 21:36, schrieb lukas:
> Question #244068 on python-mode.el changed:
> https://answers.launchpad.net/python-mode/+question/244068
>
> Status: Answered => Open
>
> lukas is still having a problem:
> I believe the description might be confusing due to launchpad removing
> some of the white spaces, using non monospace font and wrapping text, as
> it looks especially in the quote attached to your message.
>
> Please instead check this paste http://paste.debian.net/plain/82417
>
> The numbers mark positions where the cursors (point) is placed in the
> order:
>
>
> hit RET at the end on the 3rd line ---> moves cursor to the position marked by 1

Saying line x, pos y would be more precise

  on the 4th line
>
> then hit BACKSPACE on the 4th line ---> cursor goes to position marked
> by number 2 on the 4th line
>
> hit RET when cursor on position marked by number 2 ---> cursor goes to
> position marked by number 3 on the 5th line
>
> then again hit BACKSPACE ---> cursor goes to position marked by number 4
> on the 5th line
>
>
> How to make the cursor move 1-2-4 instead of the current 1-2-3-4?
> How to make it stay in column of numbers 2, 4 instead of jumping on every next press of RET back to the column with numbers 1,3?
>
> The numbers 1, 2, 3, 4 of are not a part of the code. I placed them in
> text only to mark the positions of the cursor/point. Hope this all make
> it clearer.
>
>
> Answering your question:
> C-j calls the command py-new-line-and-indent so it results exactly in the same behavior i describe above, which i would like to alter.
>

Okay, so that displays a bug resp. feature request.
Remains to discuss if this should be just implemented, the default or optional.
Will implement it for testing.
Please follow a bug-report created from this.

Revision history for this message
lukas (fossrox) said :
#5

Thank you very much for the fix.

Revision history for this message
lukas (fossrox) said :
#6

Thanks Andreas Roehler, that solved my question.

Revision history for this message
lukas (fossrox) said :
#7

(PS. that last message was generated by launchpad when I pressed the button "This solved my problem", I did not wrote it.)