I am in a .py file with python major mode (syntax highlighting is working). I am trying to just use the TAB key to indent a code section. Nothing happens.

Now it would be nice for emacs to do intelligent formatting. I am not even asking that! Just asking it to move text (code) over whatever the predefined number of spaces.

I can not paste the code. The disable aggressive python indentation has been added but it did not work.

At this point, I just want a way to "indent no matter what" ..

  • 4
    Can you post a sample of the code for which it is doing nothing? Commented Mar 21, 2015 at 23:34

2 Answers 2


Sometimes if the syntax on previous lines is incorrect emacs doesn't indent. One common case is a missing colon, e.g. at the end of an if statement.

Alternatively, your current syntax is correct and adding a tab would break the code, which is why emacs isn't letting you do it.

You could always use spaces.

  • hmm. I am able to copy and paste all of the code into ipython and run it.. Commented Mar 22, 2015 at 15:34
  • @javadb a sample of your code, or other code that reproduces the problem, would be vey helpful. One possibility: It makes sense that your code, unindented, runs in iPython. Indentation would break it, which is why emacs isn't letting you do it.
    – mattsilver
    Commented Mar 22, 2015 at 15:53

With python-mode.el, which needs to be installed explicitly, customize py-tab-indents-region-p to t - default is nil.

Note, in case indent is already at outmost reasonable level, first TAB will do nothing, following TAB will shift region cycling possible indents.

  • Thanks. I do not have access to install packages on this machine. I may suggest to the sysadmin in the end if there were no zero-impact solutions. Commented Mar 22, 2015 at 15:33

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.