Navigation Menu

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

Use the located nixfmt binary for formatting. #120

Merged
merged 2 commits into from Jan 15, 2021

Conversation

znewman01
Copy link
Contributor

Allows use with nixfmt installed using direnv (envrc-mode).

Before:

  1. nix-format-buffer checks for nixfmt: (executable-find nix-nixfmt-bin)
  2. If it's missing, error. Otherwise, disregard the path to nixfmt
    that we just found.
  3. Open a new buffer (if using envrc-mode, with a totally different
    $PATH) and try to run nix-nixfmt-bin.

If you had nixfmt installed in your direnv but not globally, this
gives an error: "Searching for program: No such file or directory, nixfmt".

Now, we use the path that we just found and call-process-region on that.

Builds were failing ([example]), as `orgmode` doesn't keep all old
versions of `org-plus-contrib`.

Updated `nixpkgs.url` to 20.09 from 20.03 and ran
`nix flake update --recreate-lock-file`.

[example]: https://github.com/NixOS/nix-mode/pull/120/checks?check_run_id=1646110624
Allows use with `nixfmt` installed using direnv ([envrc-mode]).

Before:

1. `nix-format-buffer` checks for `nixfmt`: `(executable-find nix-nixfmt-bin)`
2. If it's missing, error. Otherwise, disregard the path to `nixfmt`
   that we just found.
3. Open a new buffer (if using `envrc-mode`, with a totally different
   `$PATH`) and try to run `nix-nixfmt-bin`.

If you had `nixfmt` installed in your direnv but not globally, this
gives an error: "Searching for program: No such file or directory, nixfmt".

Now, we use the path that we just found and `call-process-region` on that.

[envrc-mode]: https://github.com/purcell/envrc
@znewman01
Copy link
Contributor Author

I rebased this on #121 so tests would actually run; don't merge this until that is merged.

@akirak
Copy link
Contributor

akirak commented Jan 5, 2021

Alternatively, you could use reformatter.el to wrap nixfmt executable. It works with nix-shell and direnv-mode without any workaround. I'm not sure about envrc-mode, because I am not using it.

Here are some advantages of using reformatter.el:

  • It handles text encoding properly, so it can prevent issues when dealing with files containing e.g. CJK characters.
  • It defines a minor mode for formatting the buffer on saving.

@znewman01
Copy link
Contributor Author

reformatter.el appears to be written by the author of envrc-mode, so I'd suspect that they work together.

I think that's a great idea in the medium term, but would prefer to limit the scope of this PR.

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

Successfully merging this pull request may close these issues.

None yet

3 participants