I have a bunch of python files (ie .py files), which I use Emacs to edit. However I keep having the issue where sometimes emacs will indent regions with 8 spaces instead of 4, and I can't figure out why.
For example, sometimes when I define a function and hit return, Emacs will indent the following code by 8 spaces instead of the usual 4, and pressing TAB will only allow me to cycle between 0 indent and 8 spaces. If I manually enter 4 spaces for the first line, then following ones will appear at the same 4-space indentation, but if I then want to say put in a for loop, I will have the same issue again with the following code being indented by 8 spaces relative to the for ...: command.
I can't seem to sort this out by changing anything in my .emacs
file (though I have only been using Emacs for a few months so maybe I'm doing something wrong!) - I have tried putting in
(setq tab-width 4)
and
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function #'insert-tab)
which I found from answers to other people's questions, and neither of them have any impact. It's also an intermittent problem, it doesn't seem to happen for every file.
Hope someone can offer some help! And I apologise if this is a duplicate question, I searched around but couldn't find anyone else with the exact same issue so I don't think it is!