When I write Python code, I personally prefer indenting with 4 spaces instead of a tab. However, in my day job I work with a codebase that uses only tabs.
When I open one of these files in emacs, tabs display eight spaces wide. I have tried adding both (setq-default tab-width 4)
and (setq tab-width 4)
to my init file, but neither of these seem to have any affect on this problem. I have used whitespace-mode
to confirm that it is indeed one tab that I am seeing and not two, and that they are indeed eight spaces wide. When I check the value of the variable tab-width
from whatever buffer I am having the problem in, I get the following message:
tab-width is a variable defined in `C source code'.
Its value is 8
Local in buffer <whateverbuffer>; global value is 4
I know that I want Its value
to be 4 instead of eight, but I have not had any luck setting it. Also, in the documentation it says of tab-width
: Automatically becomes buffer-local when set
...I have a feeling my problem stems from this, but I don't quite understand what this means. Any suggestions? Thank you!
python-mode
to use atab-width
of 8, but not sure how... – elethan Oct 21 '15 at 15:22python-indent-offset
also, which should be done outside of the major-mode hook so its customized value is used whenpython-mode
first initializes. If @Nsukami_ could take a look at my draft answer (deleted) and post a proper answer, that would be appreciated. I'm still not familiar enough withpython-mode
and I don't want to steal @Nsukami_'s thunder. – lawlist Oct 21 '15 at 15:41python-indent-offset
appropriately, and settab-width
using thepython-mode-hook
- my problem was that I was usingsetq-default
instead ofsetq
. I will research the difference between these two to better understand why it wasn't working the way I had it. – elethan Oct 21 '15 at 15:44