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

时间:2011-08-17 01:12:49

标签: python emacs elisp

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 :(得分:1)

任何以将tab-width设置为8以外的其他Python缩进都注定会带来麻烦。 tab-width确定Emacs 如何显示 TAB字符,而不是 在缩短tab键时缩进

答案 1 :(得分:0)

也许你不需要解决这个问题。 Style Guide for Python Code强烈建议使用4个空格,为什么不遵循它?