emacs 中的缩进和制表符

Indentation and tabs in emacs

在我们公司,有人用Windows、OS-X和Ubuntu写代码(主要是javascript),我主要用Emacs我的文本编辑器。

但是,我对 Emacs 很陌生,我发现整个制表符与空格自定义有点混乱。

这是我朋友 Visual Studio Code 的设置文件的样子

// Place your settings in this file to overwrite the default settings
{
"editor.tabSize": 4,
"editor.insertSpaces": false,

"files.trimTrailingWhitespace": true
}

如何在 Emacs 上复制相同的设置? 到目前为止,这是我的 ~/.emacs/init.el 文件的一部分,但它仍然无法按预期工作。

;;Tab and spaces
(setq-default indent-tabs-mode nil)
(setq default-tab-width 4)

任何解决此问题的帮助 and/or 了解更多信息的正确链接将不胜感激..

你的 conf 有错误(可能是粘贴 pb)

;;Tab and spaces
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4) ;; not (setq default-tab-width 4)

此配置很好,但有时其他配置(主要模式或次要模式配置)可能会覆盖您的默认设置。

例如

  • python 使用 python-indent-offsetpython-indent(自 24.3 起已过时)。
  • C++ 使用c-indent-level
  • nxml 使用 nxml-child-indentnxml-attribute-indent.
  • ...

所以解决方案取决于语言。您需要按语言进行适当的配置。

希望对您有所帮助