Working on .py files, I know how to get emacs to use 4 spaces as an indent by default. I also know how to get it to use the tab character by default. I'd like to leave it at using spaces by default, but recognize when tab characters are used and use that instead (for my older python files). I know I can just untabify everything, but this might not be an option when working on someone else's code and they'd like to use tabs instead (for whatever reason).
I created 2 simple files consisting of:
a = 1 if a == 1: b = 1
In one file, that indent is using 4 spaces while the other file uses a tab character. I can't get Emacs to recognize the difference. I am using Elpy, but I've tried this with Elpy disabled. I've also tried this with a blank init file and having only the modifications to tab. Anyone know the solution to this?
I've been messing around with the following:
(add-hook 'python-mode-hook (lambda () (setq indent-tabs-mode t) (setq tab-width 4)))
Setting indent-tabs-mode to
t makes it always use a tab character. Setting it to
nil makes it always use spaces. I've also tried the following:
(add-hook 'python-mode-hook 'guess-style-guess-tabs-mode) (add-hook 'python-mode-hook (lambda () (guess-style-guess-tab-width)))
This will only use spaces in Python files... What do?