【问题标题】:Disable emacs from converting tabs to spaces禁止 emacs 将制表符转换为空格
【发布时间】:2020-01-29 13:24:44
【问题描述】:

我最近开始使用 Emacs,遇到的一个问题是编辑器会自动将所有制表符转换为空格。现在开始有点烦了。

这是我的.emacs 文件供参考:

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl
    (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
    (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)

(custom-set-variables
 '(custom-enabled-themes (quote (dracula)))
 '(custom-safe-themes)
 '(display-line-numbers-type (quote relative))
 '(global-display-line-numbers-mode t)
 '(menu-bar-mode nil)
 '(package-selected-packages
   (quote
    (company-irony-c-headers company-irony micgoline elpy company-jedi molokai-theme gruvbox-theme autopair auto-complete anaconda-mode nyan-mode dracula-theme company)))
 '(scroll-bar-mode nil)
 '(tool-bar-mode nil))
(custom-set-faces
 )

(setq make-backup-files nil)
(setq auto-save-default nil)
(setq inhibit-startup-message t)   ;; hide the startup message

(elpy-enable)
(pyenv-mode)
(setq python-shell-interpreter "ipython"
      python-shell-interpreter-args "-i --simple-prompt")
(require 'powerline)

关于如何阻止 emacs 执行此行为的任何建议?

【问题讨论】:

  • 你检查变量缩进标签模式了吗?有了这个,您应该能够使用空格或制表符在 emacs 之间切换。
  • @AltruisticDelay:请将其发布为答案。评论可以随时删除。
  • 如果你只想要 空格 那么indent-tabs-mode(禁用)就是你所需要的。如果您想要标签,那么您可能还需要了解其他内容,因为标签只会在每个tab-width 列中使用,这意味着您可能需要配置其他确保每个缩进都是tab-width 的精确倍数。这些东西可以特定于主模式,但M-x apropos-variable 搜索offsetindent 会很方便。 M-x customize-group 所讨论的图书馆也应该向您展示您需要了解的内容。

标签: emacs indentation auto-indent spacemacs


【解决方案1】:

根据 Drew 的建议,我将其发布为答案:

你检查变量indent-tabs-mode了吗?

有了这个,你应该能够使用空格或制表符在 emacs 之间切换。

正如 emacs wiki here 中所述,我假设,某些活动模式在您的 emacs 中将其设置为 nil。 您可以找到另一种解释,其中包含有关标签是否邪恶的讨论链接here

编辑: 奇怪的是,python 模式将indent-tabs-mode 设置为 t。 也许这个 Emacs Wiki entry 可以解决您的问题。这个来自 wiki 的 sn-p:

(add-hook 'python-mode-hook
    (lambda ()
        (setq-default indent-tabs-mode t)
        (setq-default tab-width 4)
        (setq-default py-indent-tabs-mode t)
    (add-to-list 'write-file-functions 'delete-trailing-whitespace)))

看起来它可以解决问题。 希望这会有所帮助。

【讨论】:

  • 并没有真正起作用。我将(setq-default indent-tabs-mode t) 添加到我的 .emacs 配置文件中。但它似乎也不起作用。我的文件中仍然有空格而不是制表符。
  • @Sabyasachi Bhoi:修改了我的答案以在 python 模式挂钩中设置正确的缩进。希望这能解决您的问题。
  • 还是不行。我正在编辑一个 c++ 文件以防万一。
  • 你知道最迷人的部分是什么吗?我完全删除了 .emacs 文件,但它仍然自动将我所有的制表符转换为空格 (sighs)
  • 在你的 python 缓冲区中,indent-tabs-mode 和 py-indent-tabs-mode 的值是什么?如果你在这个缓冲区中明确设置会发生什么?
猜你喜欢
  • 2013-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-04
  • 2016-08-17
  • 2010-10-02
  • 2014-04-27
  • 2013-01-24
相关资源
最近更新 更多