2

I do a lot of python coding and am trying to determine if electric indent can be customized to help me with the following scenario:

Let's say my cursor (point) is at the end of the following excerpt, at the 'X':

if (some_condition):
    do_something()
    and_do_something_else()X
return

If I hit RET, the cursor is moved to the next line immediately below the 'a'. Great. BUT... if all I want to do is insert a blank line, I will quickly move point somewhere else, and then some unwanted whitespace is left in the empty line:

if (some_condition):
    do_something()
    and_do_something_else()X
.... # <-- unwanted whitespace left here
return

Binding RET to electric-indent-just-newline does not give me what I want, because that causes the cursor, in this scenario, to go to column 0.

I guess what I'm looking for is a clean way to:

  • Automatically move the cursor to the same level of indentation as the previous line if I hit RET, BUT
  • If the subsequent line just needs to be a newline / blank line, don't poop it up with whitespace.

Or do I need to resort to calling the function that deletes trailing whitespace?

Please let me know if I need to clarify the problem I'm trying to solve.

3
  • 1
    Try using C-o to add a newline after point and then move it somewhere else.
    – user12563
    Commented Jun 26, 2018 at 20:56
  • @DoMiNeLa10 Awesome - this actually will get me what I need - I just need to develop the habit. Thanks!
    – Larold
    Commented Jun 26, 2018 at 21:33
  • In that case, I'll post it as an answer.
    – user12563
    Commented Jun 27, 2018 at 15:53

1 Answer 1

3

You can add just a newline after point with open-line, which is bound to C-o by default, and it will work in pretty much every major mode out there. It might take a little bit before you get used to it, but it saved me a LOT of keystrokes and time because of how often I need to perform such an operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.