2
votes

I have set up my emacs for python development. I use elpy and other tools such as autopep8, pylint and flycheck to get feedback from emacs for syntactic and style issues. I use spaces for indentation which is the suggested approach (pep8). Everything works just fine.

At job we use tabs for indentation and I want to set up my emacs for that. I added the following to my emacs and it seems to work OK.

(add-hook 'python-mode-hook
(lambda ()
   (setq indent-tabs-mode t)
   (setq python-indent 4)
   (setq tab-width 4)))

The problem is that after adding these lines I get a number of issues with pylint, autopep8 etc.

For example, pylint complains for the use of tabs, autopep8 automatically fixes tabs and replaces them with spaces and a number of other errors related to the fact that I use tabs instead of spaces.

I could disable some of the error checks (e.g. E123 etc.) and then I could possibly make it work with pylint, autopep8, flycheck etc. Actually I tried it a little bit and I think I could make it work but it seems like a 'brutal' approach.

Is there an elegant/neat way to make emacs work with tabs instead of spaces for indentation in python and at the same time avoid as much as possible complaints from other plugins (pylint, autopep8, flycheck etc.)?

1

1 Answers

1
votes

I don't use autopep8 or flycheck, but I use pylint. You can use the --indent-string option of pylint to use tabs instead of spaces.

(setq pylint-options (append pylint-options '("--indent-string='    '")))