I use elpy
package for Python 3 in Emacs. It uses yapf
to format a Python buffer. I have tried about everything, setting tab-width
to 2 and setting python-indent-offset
to 2 but nothing makes it so that when I run elpy-format-code
the code is format using two spaces.
I have this in init file,
(set-default tab-width 4)
But I also set it locally within my use-package declaration for elpy. Here are my elpy configs.
;; elpy
(use-package elpy
:ensure t
:init
(elpy-enable)
(setq python-shell-interpreter "python3"
elpy-rpc-python-command "python3"
python-shell-completion-native-enable nil
elpy-shell-starting-directory 'current-directory
python-remove-cwd-from-path nil
;; don't prompt before running compile
compilation-read-command nil)
;; to keep the unhelpful warning from *Flymake log* buffer
(remove-hook
'flymake-diagnostic-functions
'flymake-proc-legacy-flymake)
:hook
(elpy-mode . (lambda ()
(setq tab-width 2
python-indent-offset 2)
(highlight-indentation-mode -1))))