Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make ocamlformat use .ocamlformat file from a specific directory? #573

Closed
utkarshkukreti opened this issue Jan 28, 2019 · 4 comments

Comments

@utkarshkukreti
Copy link

Context

I wrote the initial ocamlformat <-> atom-beautify integration a while back. I'm trying to make it support reading .ocamlformat config from the project folder.

Problem

atom-beautify (with beautify on save mode) formats the file before it's saved to disk. The implementation above saves the contents of the file to a temporary file, calls ocamlformat binary on it, and then sends the output back to the editor before the file is saved. This method does not read the correct .ocamlformat file because the temporary file is not stored in the same directory as the original file.

Question

Is it possible to specify which directory to scan for the .ocamlformat file while specifying a different file as input?

I tried passing --root but it doesn't work because passing a root argument presumably enables --disable-outside-detected-project automatically:

$ ocamlformat --root=/path/to/original/file's/directory /tmp/a.ml
File "/tmp/a.ml":
Warning: Ocamlformat disabled because [--disable-outside-detected-project] was given and no project root was found
...
@jberdine
Copy link
Collaborator

Yes, using --name should work, see https://github.com/ocaml-ppx/ocamlformat/blob/master/ocamlformat-help.txt#L250 .

And thanks for the atom-beautify integration!

@utkarshkukreti
Copy link
Author

Thanks, that worked great! I've added this change to my latest atom-beautify PR: Glavin001/atom-beautify#2257.

@jberdine
Copy link
Collaborator

jberdine commented Apr 1, 2019

@utkarshkukreti I failed to mention this before, but please feel free to send a PR with an addition to the README.md file that points to your atom-beautify integration.

@Wilfred
Copy link
Contributor

Wilfred commented Nov 7, 2019

I hit this issue today, and ended up using --name rather than --root. I'm struggling to find a use case for --root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants