1

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.

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

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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