如何为.py文件将Emacs选项卡大小设置为4个字符宽?

Nic*_*ton 26 emacs

我尝试过使用以下内容:

(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))
Run Code Online (Sandbox Code Playgroud)

但是编辑.py文件时标签的大小仍然是8个字符宽.在其他文件中,它已降至4,所以我认为Python主要模式以某种方式覆盖了这一点.我看到我可以将python-indent设置为4,但这会导致插入空格(这违反了我们的代码样式指南).

如何使标签4个宽度?

更新:

我也试过这个,但它没有做任何事情:

(add-hook 'python-mode-hook
  (setq indent-tabs-mode t)
  (setq tab-width 4)
)
Run Code Online (Sandbox Code Playgroud)

Tao*_*eng 46

(add-hook 'python-mode-hook
      (lambda ()
        (setq indent-tabs-mode t)
        (setq tab-width 4)
        (setq python-indent-offset 4)))
Run Code Online (Sandbox Code Playgroud)

  • 标签是无尽的头痛.我建议使用:"(setq indent-tabs-mode nil)" (16认同)