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

Support formatters with different working directories #5

Open
pmiddend opened this issue Feb 28, 2019 · 8 comments
Open

Support formatters with different working directories #5

pmiddend opened this issue Feb 28, 2019 · 8 comments

Comments

@pmiddend
Copy link

I, unfortunately, have a formatter that requires it to be run from the project's root directory. In my hand-written formatter, I pass projectile-project-root to the started subprocess. reformatter.el doesn't seem to support this. Any way to implement this easily?

@wbolster
Copy link
Contributor

wbolster commented Apr 21, 2019

quote from the comments in the package:

The :args" and :program expressions will be evaluated at runtime

perhaps you can use this to create a :program that will execute something like this:

sh -c 'cd "..." && your-formatter'

@purcell
Copy link
Owner

purcell commented Apr 22, 2019

Hi @pmiddend! Which formatter is that? It's unusual to have a formatter which works on STDIN/STDOUT but needs to be run from the root of a project.

Since reformatter currently only suggests STDIN/STDOUT reformatters, it would probably be quite easy for me to override the working directory as a result of, say, a new :workdir fn option.

perhaps you can use this to create a :program that will execute something like this:

Ah, this won't work, because "program" must be the actual executable, not a command string, since it's passed to call-process.

@purcell
Copy link
Owner

purcell commented Apr 22, 2019

(Funnily enough, I contributed the code which allows flycheck to run checkers from different working directories, and that was horribly fiddly to get right.)

@pmiddend
Copy link
Author

@purcell it's https://github.com/asottile/reorder_python_imports and I admit it's pretty strange

@purcell
Copy link
Owner

purcell commented Apr 28, 2019

The source code of that script suggests that it doesn't use STDIN/STDOUT anyway, so presumably you're passing it arguments that rely on (buffer-file-name)? If so, that's already a bit of a hack. :-)

@pmiddend
Copy link
Author

pmiddend commented Apr 28, 2019

It actually does use STDIN/STDOUT, though I completely understand that you want to limit reformatter.el's scope and not support every hacky formatter out there ;)

@wbolster
Copy link
Contributor

what about my earlier comment, but use /bin/sh as the executable, and do the "cd ... && ..." part in :args?

@victorolinasc
Copy link

@purcell first of all, thanks a lot for this code! It really helps :)

I'll build the case for this feature with a valid case of a non-awkward formatter.

Elixir Mix Format task

Using reformatter.el with mix is a breeze.

(reformatter-define elixir-format
    :program "mix"
    :args '("format" "-"))

It just works.

The problem is with a specific optionm import_deps where dependencies can contribute to the formatting rules applied in the project. To use this option, the mix format command must be run in the same directory as the mix.exs file that defines those dependencies. Now add to that that one of the most famous framework in the language add this option upon project generation (scaffolding)... then it is a bit of a pain...

This could be thought as a valid pattern in other languages too. I'd really appreciate if this could be built in reformatter.el. It has been a very though ride to get this right in emacs-elixir... (see here and here for instance...).

Thanks once again for your wonderful work on Emacs.

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

4 participants