1

When I have a brief if-else statement where each action is a single line, I like to use the format:

    if( cond ): print "True"
    else:       print "False"

I personally find this to be the most, elegant, concise and readable. Emacs, however, does not agree. It wants to indent it as:

    if( cond ): print "True"
else:       print "False"

Is there any way to change this behavior? I'm using emacs 24.3.1, and the python.el major-mode.

7
  • My Emacs configuration for Python 3.3 handles it correctly (then again, Emacs 24.2.1). Commented Oct 26, 2013 at 20:52
  • Might there be another problem in the code before? It would then often result in this kind of behavior. Commented Oct 26, 2013 at 20:53
  • check what M-x indent-region does when you just select the two lines. Commented Oct 26, 2013 at 20:54
  • @Dualinity no, this is very consistent recurring behavior Commented Oct 26, 2013 at 20:55
  • 1
    I see the same behavior as OP in emacs 24.3.1 Commented Oct 26, 2013 at 23:53

1 Answer 1

0

In Emacs-24.3, every time I hit TAB on the `else' line, it switchwes between the two indentations (the correct one and the incorrect one). So there's indeed a bug in that the incorrect indentation should not be suggested, but at least the correct indentation is among the choices offered.

Maybe it's related to http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15163.

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting; I'm not even getting the correct indentation as an option. I did submit a bug report, but I don't think it has been posted yet.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.