2
votes

I've got one Python source file which has somehow "remembered" the wrong indent mode. If I do "emacs foo.py", and then immediately do "c-h v indent-tabs-mode", it says, "Its value is t". All other python source files come up with indent-tabs-mode nil.

I do not have any literal tabs in the file. If I insert any new text, the indentation is done using tabs. At some point in the past, I did save (and check into version control) a version of the file which had tabs in it.

I'm using python-mode.el, version 5.1.0, and GNU Emacs 23.3.1. The file does open in Python mode.

What is going on here? Where has emacs stored some bit of state saying to set indent-tabs-mode for just this one file, and how did it get set in the first place?

2
You can also specify local variable if you need: gnu.org/software/emacs/manual/html_node/emacs/… - mathk
I suggest you check your .emacs file to see if it sets indent-tabs-mode somewhere, maybe at top-level or within an eval-after-load. - Stefan

2 Answers

3
votes

Check the source tree for any .dir-locals.el files. These may be overriding your default python-mode settings.

See the documentation on Directory Variables.

0
votes

OK, I think I figured this out. There was no .dir-locals.el file, but I can reproduce the behavior. Start with:

if foo:
        print "this line is indented with 8 spaces"

and save that into foo.py. Open foo.py again, go to the end of the print line, and hit return to create and auto-indent another line. That line gets indented with a tab! I don't know how I originally got the line indented with 8 spaces (I use 4 spaces for indents), but that seems to be what's causing this to happen.

Manually fixing up the 8-space indent to be 4 spaces and saving the file solved the problem.

I imagine tabnanny or pylint would have found this.