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

标签 emacs tabs indentation auto-indent

我无法让 Emacs 运行并将 Python(或任何环境)设置为 4 个空格的制表符。下面是我的 .emacs文件,我已经尝试了 ;; --- Set python indent to 4 spaces --- 下的所有选项,并且他们都没有工作。缩进是否可能发生一些冲突或覆盖?

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

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

(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 ---

最佳答案

从 C-h v default-tab-width RET

This variable is obsolete since 23.2; use `tab-width' instead.



tab-width

Documentation:
*Distance between tab stops (for display of tab characters), in columns.
You can customize this variable.



当我插入
(custom-set-variables
 '(tab-width 4))

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

关于Emacs 不会将任何语言的缩进设置为 4 个空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14419147/

相关文章:

emacs - 如果名为 "xyz"的帧存在,则切换到该帧

android - 跨平台正确的 Android 选项卡外观?

java - 有没有办法在 Java 中强制使用制表符而不是空格?

jquery - 如何修复 Vim 中 Jquery 脚本的缩进?

python - 如何在 Python 中编写一个空的缩进 block ?

emacs - 如何获取 elisp 时间指定的月份中的天数?

emacs - 为 Windows/C++ 程序员学习 Common Lisp 技巧

emacs - 如何关闭 go 缓冲区中的 ‘tab’ 突出显示?

javascript - Magento : Moving content to the review tab on the product page

Html 标签属性缩进最佳实践?