Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a tab width for JSON files?

Tags:

I have the following in my .emacs file. But it doesn't change the tab width in .json files.

(setq-default indent-tabs-mode nil) (setq-default tab-width 2) (setq standard-indent 2) 

I'm using emacs 24.3 on OS X 10.8.4

like image 475
resting Avatar asked Jul 27 '13 19:07

resting


People also ask

How do I change the tab spacing or code?

Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately.

What is tab size in VS Code?

VS Code lets you control text indentation and whether you'd like to use spaces or tab stops. By default, VS Code inserts spaces and uses 4 spaces per Tab key. If you'd like to use another default, you can modify the editor.insertSpaces and editor.tabSize settings.


2 Answers

(add-hook 'json-mode-hook           (lambda ()             (make-local-variable 'js-indent-level)             (setq js-indent-level 2))) 

Make the variable buffer local so that it does not conflict with js-mode for JavaScript files.

like image 117
Jackson Avatar answered Sep 19 '22 01:09

Jackson


I used M-x customize as mentioned here: How to change the indentation width in emacs javascript mode

It inserted '(js-indent-level 2)) into my .emacs file.

But thanks for the response anyway.

like image 39
resting Avatar answered Sep 18 '22 01:09

resting