如何在Emacs中让js2-mode使用空格而不是制表符?

23

我正在使用js2-mode在Emacs中编辑JavaScript,但似乎无法停止使用制表符而非空格进行缩进。我的其他模式工作正常,只有js2有问题。

3个回答

25

你的.emacs中是否有以下代码:

(setq-default indent-tabs-mode nil)

当我这样做时,在emacs23.0.60.1中它可以正常工作。js2-mode使用标准的emacs函数indent-to进行缩进,该函数会考虑到indent-tabs-mode。


10

在加载js2模式后,在你的.emacs文件中添加以下内容:

(setq js2-mode-hook
  '(lambda () (progn
    (set-variable 'indent-tabs-mode nil))))

5

在我的GNU Emacs 24.2.1版本中,设置:

(setq-default indent-tabs-mode nil)

.emacs 文件中的设置对于 JavaScript 模式来说不足够,可能是因为该设置在每个缓冲区上下文中被覆盖了。以下更改是足够的:

(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.
 '(indent-tabs-mode nil))

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接