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.

1 Answer 1

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

1
  • 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, 2016 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.