0

I'm running Emacs 25.2.2 on Ubuntu 18.04 for WSL. I launch emacs -q and open a new Python file, test.py. As soon as I hit the Tab key, I notice the indentation is 8 spaces instead of 4. I don't like that.

I run describe-variable to check on python-indent and I see:

python-indent is a variable defined in ‘python.el’.
Its value is 8
Local in buffer test.py; global value is 4

    This variable is an alias for ‘python-indent-offset’.   
    This variable is obsolete since 24.3; 
    use ‘python-indent-offset’ instead.`

[...]

As for the preferred variable:

python-indent-offset is a variable defined in ‘python.el’.
Its value is 4

[...]

Am I correct to think that this is a major bug in the default Python mode? What's the simplest fix or workaround?

2

The default is 4 spaces:

(defcustom python-indent-offset 4
  "Default indentation offset for Python."
  ...

But python-mode guesses the spaces when opening a file and overwrites the default locally. That's probably what happens in your case as only the local value is set to 8 and the global (default) is still 4.

Try it with a new empty file and check the value of the variable again.

You can also disable this feature:

(setq python-indent-guess-indent-offset nil) ; default is t
|improve this answer|||||
  • Not sure how I did that but when I adjusted the file by manually re-spacing and re-opening it, the issue went away... Thanks! – Brian Z Sep 21 '19 at 13:15
1

I cannot reproduce this using "emacs-24.2 -q ", where the default is correct at the value 4. I suggest you update your emacs, or perhaps there is something odd about your file test.py if it is an already existing python file.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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