Why am I getting one too many tabs in Emacs?
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")
(pr开发者_开发知识库ogn (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)))
I'm trying to setup my emacs to tab to the right level on my python code, but it adds in extra tab. It's consistant. If there should be 4 tabs, I get 5. Any suggestions?
for example
def func:
# This is where it puts me
# This is where it SHOULD put be
Any Python indentation which starts with setting tab-width
to something else than 8 is doomed to bring trouble. tab-width
determines how Emacs displays the TAB character, not how far to indent in response to hitting the tab
key.
Maybe you don't need to solve this problem. Style Guide for Python Code strongly recommends using 4 spaces, why not follow it?
精彩评论