How do I get js2-mode to use spaces instead of tabs in Emacs?

Deadly 提交于 2019-12-03 14:57:06

问题


I am using js2-mode to edit Javascript in Emacs, but I can't seem to get it to stop using tabs instead of spaces for indentation. My other modes work fine, just having issues w/ js2.


回答1:


Do you have

(setq-default indent-tabs-mode nil)

in your .emacs? It works fine for me in emacs 23.0.60.1 when I do that. js2-mode uses the standard emacs function indent-to, which respects indent-tabs-mode, to do its indenting.




回答2:


Add this to your .emacs file somewhere after you load js2 mode:

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



回答3:


On my copy of GNU Emacs 24.2.1, setting:

(setq-default indent-tabs-mode nil)

in .emacs is not sufficient for javascript mode, presumably because the setting is somehow being over-ridden in a per-buffer context. The following change is sufficient:

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


来源:https://stackoverflow.com/questions/45861/how-do-i-get-js2-mode-to-use-spaces-instead-of-tabs-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!