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

Pat*_*hie 22 javascript ide emacs js2-mode

我正在使用js2-mode来编辑Emacs中的Javascript,但我似乎无法让它停止使用制表符而不是空格来缩进.我的其他模式工作正常,只有问题w/js2.

Pet*_*sel 23

你有没有

(setq-default indent-tabs-mode nil)

在你的.emacs?当我这样做时,它在emacs 23.0.60.1中对我很好.js2-mode使用标准的emacs函数indent-to,它遵循indent-tabs-mode来进行缩进.


小智 10

.emacs加载js2模式后,将其添加到您的文件中:

(setq js2-mode-hook
  '(lambda () (progn
    (set-variable 'indent-tabs-mode nil))))
Run Code Online (Sandbox Code Playgroud)


小智 5

在我的 GNU Emacs 24.2.1 副本上,设置:

(setq-default indent-tabs-mode nil)
Run Code Online (Sandbox Code Playgroud)

在 .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))
Run Code Online (Sandbox Code Playgroud)