I'm working with a bunch of Python programmers who use vim and they make Python using TABs for indent. I use Emacs with python-mode which translates the tab key to 4 spaces (like it should, but never mind). Since I don't want to cause trouble I want to add something to my .emacs file (or whatever) to make indents using real TABS instead of translating them to spaces. How?
I'm sorry if this is answered somewhere else: I didn't find it.
You can define Python-specific settings in your ~/.emacs
with python-mode-hook
. In order to use tabs for indentation, you could use:
(add-hook 'python-mode-hook
(lambda () (setq indent-tabs-mode t)))
Since python.el
indents only 4 columns, by default, the above will use tabs when the indent is a multiple of 8 and tabs followed by spaces for other indents.
If you need to use a single tab for every indent level, you'll also need to set python-indent
to 8. Then you can set tab-width
to whatever width you want to see the tabs displayed as.
(add-hook 'python-mode-hook
(lambda ()
(setq indent-tabs-mode t)
(setq python-indent 8)
(setq tab-width 4)))
probably need to do this in python mode:
(setq indent-tabs-mode t)
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