I've tried using the following:
(setq-default tab-width 4) (setq-default tab-stop-list (list 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60))
But the size of tabs when editing .py files is still 8 chars wide. In other files it has gone down to 4, so I assume the Python major mode is overriding this somehow. I see that I can set python-indent to 4, but this causes spaces to be inserted (which goes against our code style guide).
How do I make the tabs 4 chars in width?
I've also tried this, but it didn't do anything:
(add-hook 'python-mode-hook (setq indent-tabs-mode t) (setq tab-width 4) )
With tab-width equal to the default value of 8, Emacs would insert 1 tab plus 2 spaces. Use t rather than nil to tell Emacs to use tab characters where appropriate. If you only want this in a particular mode, add (setq indent-tabs-mode nil) to that mode's hook.
This is because standard tabs are set to eight spaces. Tabs are special characters.
By default the tab size is 4 chars. The python 2 interpreter itself expands tabs to 8 chars, not 4. The Linux terminal ('cat' a python source file) and Windows (type a python source file) also expand tabs to 8 spaces.
(add-hook 'python-mode-hook (lambda () (setq indent-tabs-mode t) (setq tab-width 4) (setq python-indent-offset 4)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With