2

I have several Javascript projects, where some projects use 2 spaces for indentation and other projects use 4 spaces for indentation. Is there a project-specific way to set the indentation?

I am able to manually resolve this issue for each project by running (js2-basic-offset 2) or (js2-basic-offset 4), but can I configure this setting on a per-project basis?

Perhaps there is a dot-file that I can add to my project's root folder where I can configure settings?

I use js2-mode with tern-js if that helps. And for the record, I love it! But I would love to be able to customize this minor detail.

modulitos
  • 2,432
  • 1
  • 18
  • 36

1 Answers1

5

Perhaps there is a dot-file that I can add to my project's root folder where I can configure settings?

Yes. It is called "Per-Directory Local Variables" aka ".dir-locals.el".

Create a file named .dir-locals.el in the project root directory and have project specific configurations in it. More info (https://www.emacswiki.org/emacs/DirectoryVariables)

You should put ((js-mode (js2-basic-offset . 2))) inside the .dir-locals.el file

Hariharan
  • 473
  • 3
  • 7
  • 1
    Great answer! And it's not just tern/js2-mode specific - it applies to many other use cases as well. I learn a little more about emacs every day :) – modulitos Jun 26 '16 at 22:39