Skip to content

Replace custom nixfmt wrapping with reformatter - #176

Merged
matthewbauer merged 1 commit into
NixOS:masterfrom
lafrenierejm:reformatter
Jan 12, 2023
Merged

Replace custom nixfmt wrapping with reformatter#176
matthewbauer merged 1 commit into
NixOS:masterfrom
lafrenierejm:reformatter

Conversation

@lafrenierejm

@lafrenierejm lafrenierejm commented Dec 13, 2022

Copy link
Copy Markdown
Contributor

reformatter here refers to https://github.com/purcell/emacs-reformatter.

Note that as currently written this PR does remove existing user-facing commands. I would be glad to do any of the following:

  1. Leave as-is and accept this as a breaking change.
  2. Do not remove the old code and instead add the new functions in addition to the old one.
  3. Create aliases from the new commands to the old ones. This would keep the code clean and avoid outright breaking the existing interface, but has a potential risk of the new functions behaving slightly differently than the existing one.

For some related previous discussions, see

@lafrenierejm

Copy link
Copy Markdown
Contributor Author

@matthewbauer Any opinions on this change?

@matthewbauer
matthewbauer merged commit 91a317e into NixOS:master Jan 12, 2023
@matthewbauer

matthewbauer commented Jan 12, 2023

Copy link
Copy Markdown
Member

Sorry, looks good! Using an external package for this seems like a good change.

chvp added a commit to chvp/nix-mode that referenced this pull request Jan 14, 2023
Since NixOS#176 nix-mode is broken for me. Melpa only picks up the dependencies in
the main nix-mode.el file, so this should fix it again.
@matthewbauer

Copy link
Copy Markdown
Member

Hi! So after discussion from Emacs ELPA, it sounds like we have an issue with using reformatter. The problem is reformatter is not included in ELPA, and since nix-mode is, including an outside hard dependency makes nix-mode not usable. So while we could require it as an optional dependency, it cannot be a hard dependency. It sounds like there is some interest in getting reformatter included in ELPA, but this could take some time and we can revisit this then.

I've decided to revert it for the time being: c18a24e

Thanks for the contribution though! I wish we could use reformatter since it simplifies things so much.

@peterhoeg

Copy link
Copy Markdown
Member

There seems to be a fair amount of momentum behind apheleia as the formatter framework to replace both format-all and reformatter (authors of all 3 frameworks are discussing it). At least with doom emacs, adding a new formatter is a one-liner:

(set-formatter! 'nixpkgs-fmt '("nixpkgs-fmt") :modes '(nix-mode))

So instead of committing to a particular framework, maybe this can be handled via documentation instead?

Full disclosure - with doom the line above is supposed to work with format-all as well, however it doesn't.

@akirak

akirak commented Apr 17, 2023

Copy link
Copy Markdown
Member

There seems to be a fair amount of momentum behind apheleia as the formatter framework to replace both format-all and reformatter (authors of all 3 frameworks are discussing it)

@peterhoeg Could you provide a link to the discussion?

@peterhoeg

Copy link
Copy Markdown
Member

@akirak

akirak commented Apr 17, 2023

Copy link
Copy Markdown
Member

@peterhoeg Thanks.

There seems to be a fair amount of momentum behind apheleia as the formatter framework to replace both format-all and reformatter (authors of all 3 frameworks are discussing it).

I have checked out the discussion at lassik/emacs-format-all-the-code#170, but apparently there is no consensus between the authors to switch to apheleia.

People should be free to choose whatever formatter frontend. I am using reformatter, and I haven't found a problem with it so far, but there may be people who prefer to use something else.

So instead of committing to a particular framework, maybe this can be handled via documentation instead?

I agree with this point. It is probably not a good idea to add an extra dependency just to save a few lines of configuration, as there are multiple options for running a formatter.

FYI, some people in the Nix community are using treefmt-nix. With treefmt, there is no need to add a formatter configuration specific to the Nix language.

@adamcstephens

Copy link
Copy Markdown

eglot/lsp-mode can also ask the language server to run the formatter. nil supports this today. I don't think it's necessary for this package to handle formatting at all.

@peterhoeg

peterhoeg commented Apr 18, 2023 via email

Copy link
Copy Markdown
Member

@purcell

purcell commented Aug 4, 2023

Copy link
Copy Markdown
Member

FWIW, reformatter should be clear to go into GNU ELPA soon (see purcell/emacs-reformatter#2), so you could restore this change in due course.

@purcell

purcell commented Sep 5, 2023

Copy link
Copy Markdown
Member

Update: reformatter is now in NonGNU ELPA, so you could presumably return to using it here if you like.

@Dietr1ch

Dietr1ch commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

FYI: This got reverted, but I'm going for a similar change in #211

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.

7 participants