Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 902
Patrick Ritchie Avatar asked Sep 05 '08 13:09

Patrick Ritchie


People also ask

How do I disable tabs in Emacs?

If you want to remove tabs in an existing file, mark the whole buffer using C-x h and use M-x untabify .

How many spaces is a tab in Emacs?

This is because standard tabs are set to eight spaces. Tabs are special characters.

How do I use tabs in Emacs?

To manually insert a tab in Emacs, use ctrl-Q TAB. control-Q causes the next key to be inserted rather than interpreted as a possible command.


2 Answers

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.

like image 62
Peter S. Housel Avatar answered Sep 28 '22 13:09

Peter S. Housel


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

(setq js2-mode-hook   '(lambda () (progn     (set-variable 'indent-tabs-mode nil)))) 
like image 39
john_fries Avatar answered Sep 28 '22 12:09

john_fries