Proposal: mix format option to print formatted input to stdout for single file without altering the file

22 views
Skip to first unread message

Francesco Belladonna

unread,
Apr 15, 2019, 8:19:09 PM4/15/19
to elixir-lang-core
Hello!
I've been happily using `mix format` since a while and wanted to add an extension to my text editor for it (well, there is one but it's not amazing).

Unfortunately I noticed there is no way for `mix format` to take a single file as input and output the result to stdout, it only changes the files directly on the filesystem.
This works practically, but the editor has ugly flickers from reloading the file from the filesystem.

Ideally, I'd be able to take some text as input and print the formatted file as output, while still using the whole `.formatter.exs` set in the project.

A few ideas:

- `cat myfile.ex | mix format`: when STDIN is used, mix will print to stdout instead of altering the file
- `mix format --stdout myfile.ex`: mix will print to stdout. If a directory is passed or multiple files are passed, an error will be printed

Does this sound reasonable? I can work on a PR myself if preferred, as long as the idea is a good one and an agreement is found for the interface

José Valim

unread,
Apr 16, 2019, 1:34:01 AM4/16/19
to elixir-l...@googlegroups.com
Hi Francesco!

The STDIN approach works, you just have to pass “-“ as input to mix format.
--


José Valim
Skype: jv.ptec
Founder and Director of R&D

Francesco Belladonna

unread,
Apr 16, 2019, 2:05:21 AM4/16/19
to elixir-lang-core
Thanks.
Apologize, I noticed is like the 3rd line in the docs. I'm not sure how I missed it, I CTRL+F searched "STDOUT" (must have incorrectly typed it), asked in chat and scrolled through the docs (missing the first line after the example) and skimmed with eyes searching for a section mentioning standard output.

Sorry for wasting your time,
Cheers!
Reply all
Reply to author
Forward
0 new messages