Emacs不会将缩进设置为任何语言的4个空格

时间:2013-01-19 21:37:51

标签: emacs tabs indentation auto-indent

我无法让Emacs表现并将Python(或任何环境)设置为4空格标签。下面是我的.emacs文件,我已经尝试了;; --- Set python indent to 4 spaces ---下的所有选项,但没有一个有效。是否有可能与缩进发生冲突或覆盖?

另外,无论我多少次将tab-stop-list变量设置为4的倍数,当我使用菜单中的“Customize Emacs”并在中设置变量时,它们总是以8的倍数结束。 emacs文件。

我正在使用GNU emacs for Mac OS X(http://emacsformacosx.com/)。

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
 '(custom-enabled-themes (quote (deeper-blue)))
 '(indent-tabs-mode nil)
 '(inhibit-startup-screen t)
 '(python-guess-indent nil)
 '(python-honour-comment-indentation t)
 '(python-use-skeletons t)
 '(speedbar-indentation-width 2)
 '(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "#181a26" :foreground "gray80" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :family "consolas"))))
 '(bold ((t (:foreground "white" :weight bold))))
 '(variable-pitch ((t (:family "Helvetica Neue")))))

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

(unless (require 'el-get nil 'noerror)
  (with-current-buffer
      (url-retrieve-synchronously
       "https://raw.github.com/dimitri/el-get/master/el-get-install.el")
    (let (el-get-master-branch)
      (goto-char (point-max))
      (eval-print-last-sexp))))

(el-get 'sync)

(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)


;; Yet another snippet extension for emacs -------------------------------------
(add-to-list 'load-path
              "~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)


;; Develop and keep personal snippets under ~/emacs.d/mysnippets
(setq yas/root-directory "~/.emacs.d/mysnippets")

;; Load the snippets
(yas-load-directory yas/root-directory)

;; Auto headers for files ---------------------------------------------------
(add-to-list 'load-path "~/.emacs.d/plugins/")
(require 'header2)
(add-hook 'emacs-lisp-mode-hook 'auto-make-header)


;; Invoke Emacs Speaks Statistics (ESS) for R
(require 'ess-site)

; automatically get the correct mode 
auto-mode-alist (append (list '("\\.c$" . c-mode)
                  '("\\.tex$" . latex-mode)
                  '("\\.S$" . S-mode)
                  '("\\.s$" . S-mode)
                  '("\\.R$" . R-mode)
                  '("\\.r$" . R-mode)
                  '("\\.html$" . html-mode)
                              '("\\.emacs" . emacs-lisp-mode)
                    )
              auto-mode-alist)

;; --- Automatically close all parens and quotes ---
(add-to-list 'load-path "~/.emacs.d/plugins/autopair")
(require 'autopair)
(autopair-global-mode) ;; enable autopair in all buffers


; Match Triple-quoting in python
(add-hook 'python-mode-hook
          #'(lambda ()
              (setq autopair-handle-action-fns
                    (list #'autopair-default-handle-action
                          #'autopair-python-triple-quote-action))))

;; --- Add autopairing of $ in latex ---
(add-hook 'latex-mode-hook
          #'(lambda ()
              (push '(?$ . ?$)
                    (getf autopair-extra-pairs :string))))


; Show column numbers
(setq column-number-mode t)

; --- Set python indent to 4 spaces ---
;; Set indent size to 4
(setq standard-indent 4)
(setq default-tab-width 4)

;; (add-hook 'python-mode-hook '(lambda () 
;;  (setq python-indent 4)))
;; (setq-default py-indent-offset 4)
;; (setq indent-tabs-mode t
;;       tab-width 4
;;       python-indent 4)

;; Python Hook
;; (add-hook 'python-mode-hook
;;           (function (lambda ()
;;                       (setq indent-tabs-mode nil
;;                             tab-width 4))))


;; --- Remove all tabs, convert them to spaces ---
(setq indent-tabs-mode nil)


;; --- Auto complete latex ---

1 个答案:

答案 0 :(得分:4)

C-h v default-tab-width RET

  

此变量自23.2以来已过时;     请改用“tab-width”。

tab-width

  

文档:
  *制表位之间的距离(用于显示制表符),以列为单位   您可以自定义此变量。

当我插入

(custom-set-variables
 '(tab-width 4))

进入~/.emacs并重新启动emacs,它设置为4