I'm very new to Emacs and I like it so far, but there is one thing that has been bugging me. Its auto-indenting has been acting pretty random.

Whenever I am on a new line and type something like:

for (

it indents one deeper than the deepest indent level (syntax error). This is happening in python-mode and c-mode, but not in text-mode. Why is this happening and how do I fix it?

  • 1
    Could you include a copy of several lines showing the indent behavior? I've tested it in c-mode, and the only time I get unusual behavior is when statements aren't ended with a semicolon.
    – user2699
    Commented Feb 7, 2015 at 5:55
  • The first step is to find out what command is called to insert the parenthesis. Do this by typing C-h k and then (, while in python-mode or c-mode. Commented Feb 7, 2015 at 13:54
  • ok wierd, now I can only reproduce in C mode, and like you said only when statements aren't ended with semicolons (I bet something else was wrong in python mode). This won't bother me much but I still think it's a bug.
    – clarkep
    Commented Feb 7, 2015 at 19:50

1 Answer 1


Without more information it is hard to say why the indentation level is incorrect.

The reason some keys indent in some modes is that those modes rebind them. For example, the open paren in C (and C-derived) modes is bound to c-electric-paren. This command inserts the paren but also reindents and maybe does some other things, depending on various settings.

You can usually discover this sort of thing using C-h k followed by the key, in a buffer of the mode in question, and then reading the docs.

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.