Tuesday, May 3, 2011

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

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.

From stackoverflow
  • 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.

  • The above solution only works if you want to use spaces for all modes. I need to use tabs to space my python files and spaces for javascript. Is there a way to modify the js2-mode's use of indent-to such that js2-mode uses spaces for indentation?

    Jouni K. Seppänen : Then don't set indent-tabs-mode via setq-default in all modes but via setq in a mode-specific hook.

0 comments:

Post a Comment