为什么我在Emacs中得到太多标签?

4 投票
2 回答
959 浏览
提问于 2025-04-16 23:45

init.el

(setq make-backup-files nil)

(add-to-list 'load-path "~/.emacs.d/")

; Add all top-level subdirectories of .emacs.d to the load path
(progn (cd "~/.emacs.d")
       (normal-top-level-add-subdirs-to-load-path))
; Third party libraries are stored in ~/.emacs.d/extern
(add-to-list 'load-path "~/.emacs.d/extern")
(progn (cd "~/.emacs.d/extern")
       (normal-top-level-add-subdirs-to-load-path))

; Python-specific enchancements
(load-library "python")

; Zenburn color theme
(require 'color-theme-zenburn)

(color-theme-zenburn)

python.el

; use tabs in files (urgh...yelp!)
;(setq-default indent-tabs-mode t)

; tab display width of 4 columns by default
; (throw everything at the wall, and eventually something will stick...)
;(setq-default tab-width 4)  ; Normal emacs tab-width
; (setq-default c-basic-offset 2) ; python-mode.el setting
;(setq-default py-indent-offset 4) ; Use Tabs, not spaces
;(setq-default py-smart-indentation nil) ; Don't try to guess tab width

(defun customize-py-tabs ()
    (setq tab-width 4
        py-indent-offset 4
        indent-tabs-mode t
        py-smart-indentation nil
   )
)

(add-hook 'python-mode-hook 'customize-py-tabs)

; Highlight useless whitespace
(add-hook 'python-mode-hook
                  (lambda () (setq show-trailing-whitespace t)))

我正在尝试设置我的emacs,让它在我的Python代码中正确缩进,但它总是多加一个缩进。这个问题一直存在。如果应该有4个缩进,我却得到了5个。有什么建议吗?

比如说

def func:
        # This is where it puts me
    # This is where it SHOULD put be

2 个回答

0

也许你根本不需要解决这个问题。Python代码风格指南 强烈建议使用4个空格,为什么不按照这个来做呢?

0

如果你在Python代码中把tab-width设置成除了8以外的其他值,那就很可能会遇到麻烦。tab-width是用来决定Emacs这个编辑器如何显示TAB字符的,而不是说按下tab键后应该缩进多少。

撰写回答